Skip to content

ASP.NET Core & IIS: 405 Method not Allowed

Category
Web Servers
Covers
.NET, IIS
Versions & support
About .NET →
On this page

The transition from the traditional ASP.NET to ASP.NET Core brought several improvements, but it also presented developers with a new set of challenges. Among these challenges, encountering a “405 Method Not Allowed” error when issuing PUT or DELETE requests to an ASP.NET Core application hosted on IIS can be particularly vexing. In this article, we’ll deep dive into understanding the reasons behind this error and how to resolve it.

Understanding the Error 405

Before diving into the specifics of the ASP.NET Core scenario, it’s crucial to understand what the “405 Method Not Allowed” error generally implies. The error is an HTTP response status code indicating that the web server has recognized the request method, but the target resource does not support it for the given URI.

Common Causes of Error 405 in ASP.NET Core on IIS

  • WebDAV Module: When hosting ASP.NET Core applications on IIS, the WebDAV module is frequently the culprit. This module is designed for authoring on the web and uses both the PUT and DELETE requests. If not configured correctly, it can interfere with applications that rely on these methods.
  • Missing or Incorrect Verb Handlers: IIS uses verb handlers to process requests. If these handlers aren’t correctly configured for PUT or DELETE, you’ll face a 405 error.

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: To get a clearer picture of the root cause, ensure your IIS server is configured to show detailed error messages. This will provide more context and possibly point directly to the offending module or handler.
  • Logging: Incorporate logging within your ASP.NET Core application. Tools like Serilog or the built-in ILogger can capture detailed logs that can offer insights into any potential issues.
  • Check Route Configurations: Ensure that your ASP.NET Core routing configurations support the methods you’re trying to invoke.

Conclusion

The “405 Method Not Allowed” error in an ASP.NET Core application hosted on IIS can be a hurdle, but with a proper understanding of its roots and the right tools at your disposal, it’s a manageable one. Always remember that your application’s needs are unique; hence, always test thoroughly after making any changes to configurations or infrastructure.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top