1

Is there a way to catch a 405 on Web API and return a custom message when the wrong Verb is sent? I am catching 500's by using ExceptionFilterAttribute. I am wanting to return a JSON or XML object.

1
  • Could you give example how the wrong Verb sent, ex: you api does not support POST when client still send POST? Commented Sep 30, 2012 at 8:01

2 Answers 2

3

HttpStatusCode.MethodNotAllowed is your friend.

http://msdn.microsoft.com/en-us/library/system.net.httpstatuscode.aspx

Check Request.StatusCode for it in your filter.

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

Comments

0

You can set it in the web.config using the customErrors element inside the System.Web.

<customErrors defaultRedirect="url" mode="On">
   <error statusCode="statuscode" redirect="url"/>
</customErrors>

Comments

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.