ASP.NET/Mono MVC4 Web API v.1 Application.
How to catch calls to undefined api methods. Calling http://localhost:52216/erp/api/undefinedmethod returns an error in the browser:
<Error> <Message> No HTTP resource was found that matches the request URI 'http:// localhost:52216/erp/api/undefinedmethod'. </Message> <MessageDetail> No type was found that matches the controller named 'undefinedmethod'. </MessageDetail> </Error>
How to catch this error to enter the database? I tried the code from the question
How to register ALL exceptions worldwide for a C # MVC4 WebAPI application?
but the Application_Error code and exception code are still not running, the error is returned by the browser. How to catch this error?
If url does not have api, for example
'http://localhost:52216/erp/undefinedmethod'
Error_ application completed correctly.
The WebAPI configuration from the VS2013 WebAPI project template is used:
public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
Update
I tried changing the answer. API controllers use Forms authorization and are decorated with a standard [Authorize] attribute. If authorization fails, the standard xml api error message
<Error> <Message>Authorization has been denied for this request.</Message> </Error>
going on. How to catch this error also?