我在我的 ASP.NET MVC3 应用程序中使用 HTTP PUT
和 DELETE
。当我在本地运行它时,一切正常;但是当我将应用程序发布到服务器时,这些方法不起作用。
是否有任何特殊设置可以使 Web 服务器支持 PUT
和 DELETE
请求?我正在使用 IIS 7.5 的共享主机。
我在 IIS 管理器
中启用了 PUT
和 DELETE
请求。 PUT
命令工作正常。但是 DELETE
仍然不起作用。我通过 jQuery
创建请求:
我在这个页面:
http://example.com/dashboard/edit-site/103323/links/
我的 AJAX 调用是:
$.ajax({
// url: same as page-url,
cache: false,
type: 'DELETE',
data: { linkid: $(link).data("linkid") },
beforeSend: function () {
// doing something in UI
},
complete: function () {
// doing something in UI
},
success: function (data) {
// doing something in UI
},
error: function () {
// doing something in UI
}
});
这将创建一个这样的请求:
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://example.com
Referer: http://example.com/dashboard/edit-site/103323/links/
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
X-Requested-With: XMLHttpRequest
使用此表单数据
:
linkid:104044
最佳答案
转到IIS 管理器 中的处理程序映射。找到 ExtensionlessUrlHandler-Integrated-4.0
,双击它。单击Request Restrictions... 按钮并在 Verbs 选项卡上,添加 DELETE
和 PUT
。
可能的 WebDav 发布者问题
您在已删除的帖子中提到您在 2008 服务器上运行,对吗?尝试删除 webDav 角色,或从您的站点 config
中禁用它:在 system.webServer
-> modules
部分,删除 WebDAVModule
模块:
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
关于c# - 如何在 IIS 中为 ASP.NET MVC 启用 HTTP PUT 和 DELETE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12440277/