I am using Application_Error() event to get all HTTP exceptions in web API. This event is returning all HTTP codes e.g."404","500" and using "Server.TransferRequest()" to transfer request to my "Error controller" for showing custom errors. But Application_Error() does not fire in case of HTTP Error "405"("The requested resource does not support HTTP method 'GET/POST/PUT/DELETE'). I want to show my own custom error in case of "405". One way to achieve this can be like this: Exposing (GET,POST,PUT,DELETE) methods for all controllers in API and return my own custom errors from these methods. But it will not be a good way to achieve the purpose. Can anybody guide me about a clean way to do this? Any help will be highly appreciated.
Handling HTTP "405" error in web api using application_error() event
1.1k Views Asked by A.Ghaffar At
1
There are 1 best solutions below
Related Questions in ASP.NET-MVC
- Can MVC.NET prevent SQL-injection at razor or controller level?
- Getting and passing MVC Model data to AngularJS controller
- Access property of an object of type [Model] in JQuery
- Entity Framework Code First with Fluent API Concurrency `DbUpdateConcurrencyException` Not Raising
- Bundling and minification issue in MVC
- ASP-MVC Code-first migrations checkbox not active
- Why does Azure CloudConfigurationManager.GetSetting return null
- Dynamic roles list in CustomAuthorize ASP MVC
- Jquery: Change contents of <select> tag dynamically
- Why web API return 404 when deploy to IIS
- MVC route URL not containing parameter
- Invalidate user credentials when password changes
- MVC : Insert data to two tables
- MVC - Only allow users to edit their own data
- Submit Button on Razor View doesn't call Action Result - MVC
Related Questions in REST
- Spring RestTemplate passing the type of the response
- .net rest service with JSON string and consumed with java client
- SuiteCRM how to retrieve all account related contacts
- http status code for failed email send
- cloud foundry - 413 Request Entity Too Large
- Why does PHP add "\r\n" to an empty string?
- WCF Service not accepting multiple body parameters
- How to send Rest GET request that contains "#" value in url parameters?
- Phalcon PHP - RESTful API
- Object of class CS_REST_Wrapper_Result could not be converted to string in CAMPAIGN MONITOR
- purchase individual items and subscriptions in the same PayPal REST API transaction
- Empty Response Received on Android POST Request
- angular load more tweets onclick
- Async vs Horizontal scaling
- Responding to an Office 365 event invite via REST
Related Questions in ASP.NET-WEB-API
- Implement Onfailure in webApi controller
- WebApi: Reading errors
- Why web API return 404 when deploy to IIS
- One Web API calls the other Web APIs
- colon(:) in url causes error in asp.net
- Make a per-web-application object available to Web API and SignalR controllers
- Using Azure MobileServices library with my own LAN WebApi
- redirect to actionResult method from an api
- How to catch postpack result to Web Api
- Exposing webapi to third party
- .net Web Api 2 Owin authentication token expires suddenly and often on IIS 8.5
- Can you use the same token in ADFS for 2 different relying parties?
- Does 'api/SomeEntity/ForOtherEntity/{otherEntityId}' break REST?
- Generic webAPI method based on parameter types of arrays
- Where can I find user identity when using webapi with Windows Authentication on IIS8
Related Questions in CUSTOM-ERRORS
- Override Spring form error messages
- Custom route for specified errors in web.config
- Where to find all possible errors in MySQLi
- From where and how do the error_level and error_message come in custom error handler function?
- Handling HTTP "405" error in web api using application_error() event
- Application_Error not hit when RemoteOnly
- Rendering ErrorPage shape manually in Orchard
- Exception not being passed to my Error Page in MVC4
- Making/forcing the Validation to fail by adding custom error Not Working in Laravel
- Custom error page only works for 404 errors
- Custom error message for input validators (using the array syntax)
- Web.config isn't showing errors remotely even with customErrors="Off" (on ubuntu/mono)
- MVC 2.0 - Custom handling of all errors to return json
- IIS 7.5 not taking notice of customErrors for 404 returned by MVC 3 app
- custom error message codeigniter doesn't show up
Related Questions in HTTPEXCEPTION
- Crashlytics Initialization ConnectionException (EHOSTUNREACH)
- Display Yii2 HttpException Message in View
- HTTPException: invalid and/or missing SSL certificate for url: https://accounts.google.com/o/oauth2/token
- Issue After URL Routing using URL Rewrite 2 Module of IIS
- Handling HTTP "405" error in web api using application_error() event
- exception message for missing @RequestBody method parameter
- Exception-User Unhandled / System.Web.HttpException
- HttpException when deleting session storage after logout
- How to troubleshoot "System.Web.HttpException (0x80004005): File does not exist"?
- Any Progress on Diagnosing “Request timed out” HttpExceptions?
- System.Web.HttpException: Unable to validate data - after publishing site
- How to catch a specific HttpException (#0x80072746) in an IHttpHandler
- How to register custom exception handler in laravel 8
- Custom HTTPExceptions with custom logging system in FastAPI Python
- Powershell script Invoke-WebRequest : Bad Request - HTTP Error 400. The request is badly formed
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I know it's a bit late, but what you want is possible with MessageHandlers:
http://www.asp.net/web-api/overview/advanced/http-message-handlers
You have to implement a
DelegatingHandlerThen you add it to your
HttpConfiguration