Diagnosis and Resolution of "405 Method Not Allowed" Error for PUT Method in IIS 7.5

Dec 01, 2025 · Programming · 11 views · 7.8

Keywords: IIS 7.5 | 405 error | PUT method | WebDAV module | Failed Request Tracing

Abstract: This article provides an in-depth analysis of the "405 Method Not Allowed" error encountered when using the PUT method for file uploads on IIS 7.5 servers. Through a detailed case study, it reveals how the WebDAV module can interfere with custom HTTP handlers, leading to the rejection of PUT requests. The article explains the use of IIS Failed Request Tracing for diagnosis and offers steps to resolve the issue by removing the WebDAV module. Additionally, it discusses alternative solutions, such as configuring request filtering and module processing order, providing a comprehensive troubleshooting guide for system administrators and developers.

Problem Background and Symptom Analysis

In IIS 7.5-based web server environments, developers often need to implement file upload functionality. A common scenario involves using the WebClient class to upload *.cab files via the PUT method. Developers may register a custom HTTP handler in Web.config, for example:

<add name="ResultHandler" path="*.cab" verb="PUT" type="FileUploadApplication.ResultHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />

However, even with the handler correctly configured, the server may return a "405 Method Not Allowed" error. The response headers indicate that only GET, HEAD, OPTIONS, and TRACE methods are allowed, such as:

Headers = {Allow: GET, HEAD, OPTIONS, TRACE
Content-Length: 1293
Content-Type: text/html
Date: Fri, 27 May 2011 02:08:18 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET}

This issue is typically related to IIS default configurations rather than application code errors. Even if the PUT method is explicitly allowed in IIS request filtering, the error may persist, indicating that a deeper module is intercepting the request.

Diagnosis Process: Using Failed Request Tracing

IIS 7.5 offers a powerful diagnostic tool—Failed Request Tracing—to help identify the root cause. When enabled, the trace logs may show information like:

<EventData>
  <Data Name="ContextId">{00000000-0000-0000-0F00-0080000000FA}</Data>
  <Data Name="ModuleName">WebDAVModule</Data>
  <Data Name="Notification">16</Data>
  <Data Name="HttpStatus">405</Data>
  <Data Name="HttpReason">Method Not Allowed</Data>
  <Data Name="HttpSubStatus">0</Data>
  <Data Name="ErrorCode">0</Data>
  <Data Name="ConfigExceptionInfo"></Data>
</EventData>

The logs clearly point to WebDAVModule as the module causing the 405 error. WebDAV (Web Distributed Authoring and Versioning) is a default IIS module designed to support extended HTTP methods like PUT and DELETE, but it can conflict with custom handlers in certain scenarios.

Solution: Removing the WebDAV Module

Based on the diagnosis, the most straightforward solution is to disable or remove the WebDAV module. This can be achieved by modifying the Web.config file:

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

This configuration removes WebDAV from the modules and handlers lists, allowing the custom PUT handler to take over requests normally. After removal, the server should respond correctly to PUT methods, and the error should no longer occur.

Alternative Methods and Additional Notes

If removing WebDAV is not feasible (e.g., if the server requires WebDAV functionality), consider other approaches. One option is to adjust the module processing order to ensure the custom handler takes precedence over WebDAV. This requires configuring module priorities in IIS Manager or using advanced URL rewrite rules.

Additionally, ensure that IIS request filtering settings are correct: in IIS Manager, check the "Request Filtering" feature to confirm that the PUT method is allowed and no other rules (such as file extension restrictions) are blocking the request. For example, verify that *.cab file types are in the allowed list.

From a programming perspective, developers should validate the usage of WebClient. Here is an example code snippet demonstrating how to properly use the PUT method for file upload:

using (WebClient client = new WebClient())
{
    client.UploadFile("http://example.com/upload.cab", "PUT", "localFile.cab");
}

This code uses the UploadFile method to specify the PUT verb, ensuring the request matches server configurations.

Conclusion and Best Practices

The "405 Method Not Allowed" error in IIS 7.5 is often caused by conflicts between the WebDAV module and custom handlers. Using Failed Request Tracing for diagnosis is key to efficient problem-solving. Removing the WebDAV module is a common solution, but server functionality needs should be assessed. Before deployment, it is recommended to validate configurations in a test environment and use IIS tools to monitor request flows. For developers, understanding IIS module interactions and HTTP method handling mechanisms is crucial to avoid similar issues and enhance system reliability.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.