Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 726
Paul Manzotti Avatar asked Sep 06 '12 12:09

Paul Manzotti


People also ask

How to handle HTTP status codes in web API projects?

In short, let's remember the following things about HTTP status codes in Web API projects: Always return the appropriate status code, however you define "appropriate". Use the shortcut methods (e.g. Ok (), NotFound (), etc.) when possible. An action that returns void will send status code 204 No Content.

What are the in-built HTTP status codes?

This article will cover the in-built HTTP Status Codes i.e., 200, 201, 204, 400, 401, 403 and 404 as well as the ones for which there is no in-built function in ASP.Net Core. HTTP Status Code 200 is used to return OK status i.e., request is completed and everything is fine. Such HTTP Response it is returned using Ok function.

What is a 207 status code?

What Is a 207 Status Code? A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate. The default Multi-Status response body is a text/xml or application/xml HTTP entity with a ‘multistatus’ root element.

What is httpresponsemessage in httpstatuscode?

We use HttpResponseMessage, like in the green display: HttpResponseMessage represents the response from the server to the client, and can be used with any of the status codes in the HttpStatusCode enumeration. In this way, we can return any of the standard status codes.


1 Answers

You can cast any int to HttpStatusCode

public HttpResponseMessage Get()
{
    var response = Request.CreateResponse((HttpStatusCode)207, "something");
    return response;
}
like image 119
Filip W Avatar answered Sep 27 '22 17:09

Filip W