Phil
Phil

Reputation: 4224

AppHarbor MVC - Unable to use HttpNoContent Status Code

I need to be able to respond to requests with a http status code of 204 but appharbor is only returning a 500 error. My controller code is executing correctly but when the code below is called, I only see a 500 error in fiddler.

protected ViewResult HttpNoContent()
{
    Response.StatusCode = (int)HttpStatusCode.NoContent;

    return View("NoContent");
}

Upvotes: 0

Views: 177

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Quote from the specification (I have put the important part in bold):

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

You are not respecting this rule. 204 status code means no content and yet you are returning a view. Try returning an EmptyResult:

protected ViewResult HttpNoContent()
{
    Response.StatusCode = (int)HttpStatusCode.NoContent;

    return new EmptyResult();
}

Upvotes: 4

Related Questions