1

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?

2
  • where you want to return the error in an attribute, filter, action, api acction? Commented Aug 13, 2013 at 23:12
  • This is in a method that returns an HttpResponseMessage. Commented Aug 14, 2013 at 11:25

2 Answers 2

2

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

return Request.CreateResponse((HttpStatusCode) 420, error);
Sign up to request clarification or add additional context in comments.

Comments

0

Try with something like this:

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

More reference on MSDN.

1 Comment

Thanks Daniele, but in my case I need to return something derived from HttpResponseMessage rather than ActionResult. Sorry if that wasn't clear from my question.

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.