如何通过web.config禁用WebDAV解决IIS7.5不支持DELETE及500报错问题
错误原因
出现500错误是因为修改后的web.config同层级下重复定义了<handlers>节点:原有配置中已存在自闭合的<handlers accessPolicy="Read, Execute, Script" />节点,后续新增的<handlers>节点属于重复定义,不符合IIS配置规范,因此触发服务端错误。
正确配置方案
需要将WebDAV移除规则合并到现有节点中,不可重复创建同名父节点,完整可用的web.config内容如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.web> <customErrors mode="Off" /> </system.web> <system.webServer> <httpErrors errorMode="Detailed" /> <defaultDocument> <files> <clear /> <add value="index.php" /> <add value="default.aspx" /> <add value="Default.htm" /> <add value="Default.asp" /> <add value="index.htm" /> <add value="index.html" /> </files> </defaultDocument> <!-- 合并handlers配置,移除WebDAV --> <handlers accessPolicy="Read, Execute, Script"> <remove name="WebDAV" /> </handlers> <rewrite> <rules> <rule name="Imported Rule 3" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite> <!-- 移除WebDAV模块 --> <modules> <remove name="WebDAVModule" /> </modules> </system.webServer> </configuration>
额外校验规则
如果修改配置后仍然不支持DELETE请求,可补充以下配置:
- 在
<system.webServer>节点下新增请求过滤规则,显式允许DELETE动词:
<security> <requestFiltering> <verbs> <add verb="DELETE" allowed="true" /> </verbs> </requestFiltering> </security>
- 若无WebDAV使用需求,可直接在服务器管理器的IIS角色服务中卸载WebDAV发布功能,从根源避免功能冲突。
内容的提问来源于stack exchange,提问作者user1995781
相关产品推荐
相关产品推荐

