Hugh
Hugh

Reputation: 1163

Returning a status code not found in HttpStatusCode enumeration

I'm working with ASP.NET MVC 4 and I need to return a status code of 420, which is not found among the HttpStatusCode enumeration values.

Usually it's simple, you do something like:

return Request.CreateResponse(HttpStatusCode.InternalServerError, error);

But what do I do when I don't have an enumeration value for the status code I want?

Upvotes: 1

Views: 1147

Answers (2)

Hugh
Hugh

Reputation: 1163

Figured it out. All you have to do is cast the integer status code to HttpStatusCode:

return Request.CreateResponse((HttpStatusCode) 420, error);

Upvotes: 2

Daniele
Daniele

Reputation: 1938

Try with something like this:

return new HttpStatusCodeResult(420,"My message");

More reference on MSDN.

Upvotes: 0

Related Questions