如何在 IIS 中为 ASP.NET MVC 启用 HTTP PUT 和 DELETE? [英] How do I enable HTTP PUT and DELETE for ASP.NET MVC in IIS?
问题描述
我在我的 ASP.NET MVC3 应用程序中使用 HTTP PUT
和 DELETE
.当我在本地运行它时,一切正常;但是当我将应用程序发布到服务器时,这些方法不起作用.
I use HTTP PUT
and DELETE
in my ASP.NET MVC3 application. When I run it in local, every thing works correctly; But when I publish the application to the server, these methods do not work.
是否有任何特殊设置可以使 Web 服务器支持 PUT
和 DELETE
请求?我在 IIS 7.5 中使用共享主机.
Are there any special settings for enable a web server to support PUT
and DELETE
requests? I'm using shared hosting with IIS 7.5.
更新:
我在 IIS manager
中启用了 PUT
和 DELETE
请求.PUT
命令工作正常.但是 DELETE
仍然不起作用.我通过 jQuery
创建请求:
I enable PUT
and DELETE
requests in IIS manager
. PUT
command work fine. But DELETE
still not works. I create requests by jQuery
:
我在这个页面:
http://domain.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
}
});
这将创建一个这样的请求:
This will create a request like this:
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://domain.com
Referer: http://domain.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
使用这个表单数据
:
With this Form Data
:
linkid:104044
推荐答案
转到 IIS 管理器中的处理程序映射.找到ExtensionlessUrlHandler-Integrated-4.0
,双击.单击请求限制... 按钮,然后在 Verbs 选项卡上,添加 DELETE
和 PUT
.
Go to Handler Mappings in your IIS Manager. Find ExtensionlessUrlHandler-Integrated-4.0
, double click it. Click Request Restrictions... button and on Verbs tab, add both DELETE
and PUT
.
可能的 WebDav 发布者问题
您在已删除的帖子中提到过您在 2008 年服务器上运行,对吗?尝试删除 webDav 角色,或从您的站点 config
中禁用它:在 system.webServer
-> modules
部分,移除 WebDAVModule
模块:
You've mention on a deleted post you were running on a 2008 server right? Try removing webDav role, or disable it from your site config
: on system.webServer
-> modules
section, remove WebDAVModule
module:
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
这篇关于如何在 IIS 中为 ASP.NET MVC 启用 HTTP PUT 和 DELETE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!