16/01/2021 by Nitesh

405 HTTP Verb Not Allowed – ASP.Net Core 3.1 and IIS

If you are using ASP.Net Core Web APIs and hosting it on IIS, the application running on your local machine may throw error as “405 HTTP Verb Not Allowed” when hosted on Production or UAT server. The server may be a Virtual Machine or a standard shared hosting. Or there may be a situation where the GET / POST requests are working but when calling PUT / DELETE requests, web APIs throw this error.

The problem lies in WebDAV module of IIS. You can get rid of the problem by modifying the web.config file as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>    
    <system.webServer>
        <modules>
            <remove name="WebDAVModule" />
        </modules>
        <handlers>
            <remove name="aspNetCore" />
            <remove name="WebDAV" />
            
            <add name="aspNetCore" 
                 path="*" 
                 verb="*" 
                 modules="AspNetCoreModule" 
                 resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath="%LAUNCHER_PATH%" 
                    arguments="%LAUNCHER_ARGS%" 
                    stdoutLogEnabled="false"
                    stdoutLogFile=".\logs\stdout" />
    </system.webServer>
</configuration>

I hope this post will save your time. Happy Coding!

Further Reading : https://docs.microsoft.com/en-us/aspnet/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications

#.Net Core#ASP.Net Core#IIS