While there were many advantages to switching from the classic ASP.NET to ASP.NET Core, there were also some new difficulties for developers. Among these difficulties, sending PUT or DELETE requests to an ASP.NET Core application hosted on IIS and receiving a “405 Method Not Allowed” error can be very frustrating. We will delve deeply into the causes of this error and provide a solution in this article.
Understanding the Error 405
Understanding the general meaning of the “405 Method Not Allowed” error is essential before delving into the details of the ASP.NET Core scenario. The error is an HTTP response status code that says that although the target resource for the specified URI does support the request method, the web server has acknowledged it.
Common Reasons for ASP.NET Core on IIS Error 405
- WebDAV Module: The WebDAV module is usually to blame when hosting ASP.NET Core applications on IIS. Using both PUT and DELETE requests, this module is intended for online authoring. Applications that depend on these techniques may be affected if it is not configured properly.
- Missing or Incorrect Verb Handlers: Verb handlers are used by IIS to handle requests. You’ll see a 405 error if these handlers aren’t set up properly for PUT or DELETE.
Solution
If your application does not require WebDAV, you can resolve many issues by simply disabling the WebDAV module. Add the following code to your web.config file:
<system.webServer> <modules runAllManagedModulesForAllRequests="false"> <remove name="WebDAVModule"/> </modules> <handlers> <remove name="WebDAV" /> </handlers> </system.webServer>
Additional Tips
- Enable Detailed Error Messages: Be sure your IIS server is set up to display comprehensive error messages in order to gain a better understanding of the underlying cause. This will give additional background information and might even identify the offending module or handler.
- Logging: Include logging in your application for ASP.NET Core. Comprehensive logs that can provide insights into potential problems can be captured by programs like Serilog or the integrated ILogger.
- Check Route Configurations: Make sure the methods you’re attempting to invoke are supported by your ASP.NET Core routing configurations.
Conclusion
With the correct knowledge of its causes and the appropriate resources at your disposal, the “405 Method Not Allowed” error in an ASP.NET Core application hosted on IIS can be overcome. Never forget that every application is different, so before making any changes to infrastructure or configurations, make sure you test everything thoroughly.