HTTP Error 405 With ASP.Net MVC and HTTP PUT on IIS 7.5

November 27, 2009 21:11 by admin

I have been doing most of my ASP.Net MVC RESTful web service development on IIS6 or IIS7. Recently however, I tried it on Windows 7 RTM using IIS7.5. Using the “Classic .Net AppPool” everything worked great. Then I tried the “DefaultAppPool” (i.e. using Integrated Mode). Everything seemed fine… until I wanted to PUT a new resource and DELETE a resource.

Without even going near my code, IIS reported back:

HTTP Error 405.0 - Method Not Allowed

The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.

Detailed Error Information

Module WebDAVModule
Notification MapRequestHandler
Handler WebDAV
Error Code 0x00000000
Requested URL http://localhost:80/RESTfulMVCWebService/Version19/UrlRouting.axd?format=xml
Physical Path C:\Projects\RESTfulMVCWebService\Version19\WebService\UrlRouting.axd
Logon Method Anonymous
Logon User Anonymous

Certainly not what I had expected! I turned on tracing to try and understand what was happening… and just as it says in the message, it appears that the UrlRoutingModule has taken the requested URL and re-pointed to UrlRouting.axd. Then the WebDAVModule decides that PUT is not allowed for this URL.

I wasted a fair amount of time looking at the Handler Mappings configuration trying to get HTTP PUT to be accepted. I removed the WebDAV handler. I added a catch all handler etc. etc. I tried enabling WebDAV, I tried disabling it. I tried giving “Everyone” read write access to directory containing the web service. Nothing seemed to work.

Really I should have looked more closely at the error message. I was looking at Handler Mappings, but the error was with the Modules. As soon as I removed the WebDAVModule, everything worked as it should. I made the change through the Internet Information Services (IIS) Manager, but I could have made the change manually in the web.config. All that was needed was to add the following:

<system.webServer>
  <modules … >
    <remove name="WebDAVModule" />
    ……
  </modules>

So why had I not seen this before when I worked with HTTP PUT? Well, previously I was using IIS7.0 (I developed on Vista) or IIS6 (when deploying to Windows Server 2003). These versions of IIS did not have WebDAV installed by default. When I was presented with a fresh install of Windows 7, it was already installed.

So… one to watch out for if you want to use IIS 7.5 to implement RESTful web services!

kick it on DotNetKicks.com


Comments (6) -

July 2. 2010 02:44

Damien White

Thanks for this.  Your post saved us time troubleshooting DELETE calls using WCF Data Services and IIS 7.5.

-Damien

Damien White

August 18. 2010 10:41

neio.zhou

Thanks a lot. I have tried for hours to find the way to enable DELETE verb in IIS 7.5 in order to host my WCF Data Services applications.  
Your Method really helps.

neio.zhou

January 22. 2011 05:06

Your Golf Fitness

It was frustrating to me too. It is because WebDAVModule is installed by default on IIS 7.5. By removing the module, you can get rid of this frustrating restriction. Simply,

Your Golf Fitness

May 5. 2011 20:26

Coffee_fan

Worked like a charm. Thanks for the research.

I also found some additional info here:

http://forums.iis.net/t/1166025.aspx

Coffee_fan

June 6. 2011 19:05

Machines For Fitness

Thanks, the tip helped me a lot.

Regards

Machines For Fitness

June 6. 2011 19:07

Machines For Fitness

Thank you for the advise

Regards

Machines For Fitness

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading