猿问

如何在IIS中为ASP.NET MVC启用HTTP PUT和DELETE?

我使用HTTP PUT和DELETE我的ASP.NET MVC3应用。当我在本地运行时,一切正常。但是当我将应用程序发布到服务器时,这些方法不起作用。


是否有使Web服务器支持PUT和DELETE请求的特殊设置?我在IIS 7.5中使用共享主机。


更新:


我在中启用PUT和DELETE请求IIS manager。PUT命令工作正常。但DELETE仍然行不通。我通过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

    }

});

这将创建如下请求:


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

与此Form Data:


linkid:104044


开心每一天1111
浏览 744回答 3
3回答

MYYA

您只需要在web.config中添加以下代码行<system.webServer>&nbsp;<security>&nbsp; &nbsp; <requestFiltering>&nbsp; &nbsp; &nbsp; &nbsp; <verbs allowUnlisted="false">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <add verb="GET" allowed="true" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <add verb="POST" allowed="true" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <add verb="DELETE" allowed="true" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <add verb="PUT" allowed="true" />&nbsp; &nbsp; &nbsp; &nbsp; </verbs>&nbsp; &nbsp; </requestFiltering></security>和<modules>&nbsp; &nbsp; <remove name="WebDAVModule" /></modules><handlers>&nbsp; &nbsp; <remove name="WebDAV" /></handlers>
随时随地看视频慕课网APP
我要回答