4

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 HTTP status description, no matter what message I give 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 over the wire, same with 200 OK. And if I select a non-existant status code, like 535 it will just return the status code without any description. I can't see that I'm doing anything wrong according to the documentation and examples I've found from other people using this .

Can anyone see what I'm doing wrong?

1
  • 1
    I think this might be related to Cassini. Try to run the code in IIS instead. Commented Apr 12, 2011 at 14:07

1 Answer 1

2

I just had the same issue and based on @Mikael's comment, I tried deploying my application to an actual IIS server, and yes, you can specify the actual Status Description and it will be returned to the client side.

Why is it different with Cassini, I'm not really sure about.

Sign up to request clarification or add additional context in comments.

3 Comments

There is really an issue in ASP.NET related to this: aspnet.codeplex.com/workitem/9767
@AlexYakunin Thanks for the info. Does that mean that is not really related to the server but more likely to the ASP.NET engine? Unfortunately the link does not provide much more information.
Actually, we've found a workaround for this problem: as far as I remember, we write HTTP 500 response directly by one of MVC action filters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.