How do I enable HTTP PUT and DELETE for ASP.NET MVC in IIS?

老子叫甜甜 提交于 2019-11-26 14:25:05
danielQ

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.


EDIT: Possible WebDav Publisher issue

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>
Heera Jaiswal

If you are getting following error in your production environment in the asp.net web api on PUT or DELETE though these methods are working fine locally.

405 - http verb used to access this page is not allowed.

Just add following settings in your server's web.config

<system.webServer>
    <handlers>
      <remove name="WebDAV" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
</system.webServer>

Cause: webDAV module blocks PUT/DELETE methods by default. So first remove this module and its handler. We first remove any existing ExtensionlessUrlHandler-Integrated-4.0 settings and add it with desired path and verbs.

You just need to add the following lines of code in your web.config

<system.webServer>
 <security>
    <requestFiltering>
        <verbs allowUnlisted="false">
            <add verb="GET" allowed="true" />
            <add verb="POST" allowed="true" />
            <add verb="DELETE" allowed="true" />
            <add verb="PUT" allowed="true" />
        </verbs>
    </requestFiltering>
</security>

AND

<modules>
    <remove name="WebDAVModule" />
</modules>
<handlers>
    <remove name="WebDAV" />
</handlers>
agent47

Finally I find the answer fluky. I changed the jQuery call to tho below and it's working well now.

$.ajax({ 
    url: this.href + "?linkid=" + $(link).data("linkid"), 
    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 
    } 
});

Do you have any explanation why a DELETE call, can't have Form Data? While on local it had and worked fine?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!