Question

According to the HttpResponseMessage documentation on MSDN, the reason phrase (as in, the "OK" part of 200 OK) should be settable. The HTTP response does let me set the reason phrase:

HttpResponseMessage response = new HttpResponseMessage(System.Net.HttpStatusCode.Conflict);
            response.ReasonPhrase = "conflict message";

However, when I consume the response on the client side as a WebResponse, I don't see my custom reason phrase. I'd expect to find it under the StatusDescription. Looking at the raw response using Fiddler, it doesn't seem that the reason phrase gets set on the server.

A helpful coworker pointed out that with action results (and derived), I could do something akin to:

new HttpStatusCodeResult(System.Net.HttpStatusCode.Conflict, "conflict message");

It seems as though that is the precise functionality I'm after, but I'm uncertain how to convince WebAPI to cooperate.

Where am I going wrong?

Was it helpful?

Solution

The ReasonPhrase does not work in Cassini. Use IIS Express rather than Cassini and you will find that the response includes the reason.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top