Cannot specify StatusMessage in HttpStatusCodeResult

I have the following controller method.

public ActionResult Save(IEnumerable<Model> models) { try { SaveModels(models); } catch (ApplicationException ex) { return new HttpStatusCodeResult(500, "error"); } return new EmptyResult(); } 

This will always return "Internal Server Error" as a description of the HTTP status, no matter what message I pass to the constructor.

Fiddler Output:

 HTTP/1.1 500 Internal Server Error Server: ASP.NET Development Server/10.0.0.0 Date: Tue, 12 Apr 2011 12:44:09 GMT X-AspNet-Version: 4.0.30319 X-AspNetMvc-Version: 3.0 Cache-Control: private Content-Length: 0 Connection: Close 

If I change the status code to 501, I get Not implemented by wire, the same with 200 OK. And if I select a non-existent status code, for example 535, it will simply return the status code without any description. I do not see that I am doing something wrong in accordance with the documentation and examples that I found with other people using this.

Can anyone see what I'm doing wrong?

+4
source share
1 answer

I had the same problem and based on @Mikael's comment, I tried to deploy my application on a real IIS server, and yes, you can specify the actual description of the state, and it will be returned to the client side.

Why it is different from Cassini, I'm not sure.

+2
source

Source: https://habr.com/ru/post/1347727/


All Articles