Paul Manzotti
Paul Manzotti

Reputation: 5147

Asp.Net 4.5 Web API - Return HTTP Status Code 207

I'm attempting to create a simple Web API controller to act as a WebDAV server, as I only want it to allow directory listings and read access to files, as well as integrate with the current authentication system we have in our system.

I've managed to get the directory and file listing working when using a WebDAV client (DAVExplorer), however mapping a network drive in Windows Explorer is just not playing ball.

Whilst I haven't worked out why this isn't working, one possibility is that when a WebDAV server returns the results of a PROPFIND request, it does so with a Http Status Code of 207 Multi Status. This doesn't appear to be in the HttpStatusCode enumerator that is used by the HttpResponseMessage object.

I've tried to find out what actually turns the HttpResponseMessage into the response returned to the browser, thinking I could implement my own version and deal with outputting the status code myself, but I've not had any luck with that so far.

Anyone got any suggestions for how I might implement an API Controller that returns a 207 status code?

Upvotes: 5

Views: 6152

Answers (1)

Filip W
Filip W

Reputation: 27187

You can cast any int to HttpStatusCode

public HttpResponseMessage Get()
{
    var response = Request.CreateResponse((HttpStatusCode)207, "something");
    return response;
}

Upvotes: 8

Related Questions