This project is read-only.

Custom ReasonPhrase

Topics: Web Api
Apr 1, 2011 at 2:04 PM

HttpResponseMessage has a property named ReasonPhrase with a public setter;

My question is if it is ok to set a custom value here? because I can't see the value I set on the clients that I have tested (so far a custom piece of code with restsharp and fiddler)

From a technical point of view, is it okey to set a reason here when returning errors like BadRequest?

According to w3:

The reason phrases listed here are only recommendations -- they MAY be replaced by local equivalents without affecting the protocol.

If not, how will you send more information about the error? in the body of the response?


Thank you very much.

Apr 1, 2011 at 4:07 PM

Yes you are free to customize the text in ReasonPhrase, just keep it to ASCII characters.  You also have the option to return more error information in the body.

Apr 3, 2011 at 12:22 AM

Hi Darrel, thanks for your response.

I think is broken in the released version, checked with fiddler and bugzilla.

It doesn't return anything there.

Apr 3, 2011 at 1:57 AM

I realize that it is not much consolation, but that bug has been fixed in the version that is scheduled to be released around the time of Mix.  

Jun 28, 2011 at 1:37 AM

Any update on this?

would be very useful to customize the ReasonPhrase from the server.

I downloaded the latest code shown in Mix but still same thing.




Jun 28, 2011 at 2:09 AM

It is working fine in the last bits.


new HttpResponseMessage(201, "Created the resource foooo blablabla")

Jun 28, 2011 at 2:45 AM

It works from self-hosted stuff.  But when I tried using the HelloResource sample running in Cassini, it did not return the customized reason phrase.

Jun 28, 2011 at 9:54 PM

By "last bits" you mean any specific version? I am using the web.api.all but the following code doesn't return the reasonPhrase, it returns Bad Request.

            Guid outlocationid;
            Contact contact = new Contact();
            HttpResponseMessage<Contact> Response = new HttpResponseMessage<Contact>(contact);

            if (!Guid.TryParse(locationid, out outlocationid))

                Response.StatusCode = HttpStatusCode.BadRequest;
                Response.ReasonPhrase = "Invalid Parameter";


Jun 28, 2011 at 10:26 PM

I tried with the preview 4 (which is the download package in this site) and it work for us.

I used something like

  return HttpResponseMessage(HttpStatusCode.BadRequest, "Invalid parameter")

Want to see an example?

Easy. Order beer in my restbucks example with fiddler as follows:

or simple copy and paste the xml from here: and change "latte" with "bear"

you will get a response like this:

You can digg in the source code to see what I did, but it is simply like the code pasted above and It is not running "self hosted" it is running as a web application in apphabor.

Jun 29, 2011 at 12:33 AM

Does it make any difference if we add a Type?

HttpResponseMessage<Contact> instead of plain HttpResponseMessage?

Jun 29, 2011 at 3:42 AM

try it.

Jun 29, 2011 at 7:49 PM

:) I tried it and didn't get the reasonphrase back that's why I asked. 

Aug 10, 2011 at 7:24 AM

Hi to all

I'm hosting my project on IIS and I couldn't get the reason phrase. I was using Chrome console to analyse the response but I was always receiving the status code. Nothing more. Then I started Fiddler and "magically" the reason phrase was there. I went back to Chrome and the reason phrase was there too. I closed Fiddler and it's gone again.

Anyone knows what is going on? Why Fiddler makes reason phrase work? Is it's proxy?

I really need the reason phrase. Every time an exception is thrown on server the UI developer receives a 400 or a 500, but no explanation.