ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8

前端 未结 19 1898
Happy的楠姐
Happy的楠姐 2020-11-22 05:16

I recently upgraded from Visual Studio 2010 to the Visual Studio 2012 RC. The installer also installs IIS 8 Express which Visual Studio now uses as the default web server.

相关标签:
19条回答
  • 2020-11-22 06:02

    The another reason can be the following:
    I changed my Url for Web Api method according to this answer:

    Url.Action("MyAction", "MyApiCtrl", new { httproute = "" })
    

    But this method creates link like:

    /api/MyApiCtrl?action=MyAction
    

    This works correctly with GET and POST requests but not with PUT or DELETE.
    So I just replaced it with:

    /api/MyApiCtrl
    

    and it fixed the problem.

    0 讨论(0)
  • 2020-11-22 06:05

    Remove the WebDAV works perfectly for my case:

    <modules>
      <remove name="WebDAVModule"/>
    </modules>
    <handlers>
      <remove name="WebDAV" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" 
           type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    

    it always better to solve the problem through the web.config instead of going to fix it through the iis or machine.config to grantee it wouldn't happen if the app hosted at another machine

    0 讨论(0)
  • 2020-11-22 06:07

    I am using an ashx file in an MVC application and none of the above answers worked for me. IIS 10.

    Here's what did work. Instead of changing "ExtensionlessUrl-Integrated-4.0" in IIS or web.config I changed "SimpleHandlerFactory-Integrated-4.0" for "*.ashx" files:

    <add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" 
    verb="GET,HEAD,POST,DEBUG,PUT,DELETE" 
    type="System.Web.UI.SimpleHandlerFactory" 
    resourceType="Unspecified" requireAccess="Script" 
    preCondition="integratedMode,runtimeVersionv4.0" />
    
    0 讨论(0)
  • 2020-11-22 06:10

    After endless searching and trying the already supplied answers (adding the PUT,DELETE verbs and remove WEBdav) it just didn't work.

    I went to IIS logging settings: > View Log Files. In my case W3SVC4 was the folder with the latest date, opened the folder, looked up the latest log file and saw this entry: GET /Rejected-By-UrlScan ~/MYDOMAIN/API/ApiName/UpdateMETHOD

    The Update method was listed with verb GET, weird right? So I Googled for Rejected-By-UrlScan and found this link: UrlScan Broke My Blog.

    I went to here: %windir%\system32\inetsrv\urlscan\UrlScan.ini

    Basically, the UrlScan blocked PUT and DELETE verbs. I opened this INI file, added the PUT and DELETE to the AllowVerbs and removed them from the DenyVerbs listings. I saved the INI file and it worked! So for me these steps were necessary next to the ExtensionlessUrlHandler hints.

    Windows Webserver 2008 R2 (64 bit), IIS 7.5. I'm using this in combination with DotNetNuke (DNN) WebAPI. ASP.Net 4.0 My update method:

    [HttpPut]
    [DnnAuthorize(StaticRoles = "MyRoleNames")]
    public HttpResponseMessage UpdateMETHOD(DTO.MyObject myData)
    
    0 讨论(0)
  • 2020-11-22 06:10

    I have faced the same issue with you, then solved it, Here are solutions, I wish it maybe can help
    First

    In the IIS modules Configuration, loop up the WebDAVModule, if your web server has it, then remove it

    Second

    In the IIS handler mappings configuration, you can see the list of enabling handler, to choose the PHP item, edit it, on the edit page, click request restrictions button, then select the verbs tab in the modal, in the specify the verbs to be handle label, check the all verbs radio, then click ok, you also maybe see a warning, it shows us that use double quotation marks to PHP-CGI execution, then do it

    if done it, then restart IIS server, it will be ok

    0 讨论(0)
  • 2020-11-22 06:10

    You can convert your Delete method as POST as;

     [HttpPost]
     public void Delete(YourDomainModel itemToDelete)
     {
     }
    
    0 讨论(0)
提交回复
热议问题