IIS 10.0 Detailed Error - 404.0 for [httpDelete] [

2019-02-26 12:22发布

问题:

I'm trying to make an api in ASP.NET MVC. Unfortunately I have problem with two HTTP requests: DELETE and PUT

    [ActionName("Index")]
    [HttpGet]
    public String Index()
    {
        return "get";
    }

    [ActionName("Index")]
    [HttpPost]
    public String IndexPost()
    {
        return "create";
    }


    [ActionName("Index")]
    [HttpPut]
    public String IndexPut()
    {
        return "update";
    }
    [ActionName("Index")]
    [HttpDelete]
    public String IndexDelete()
    {
        return "delete";
    }

GET and POST requests are working perfectly fine when I'm trying to sent DELETE OR PUT then browser returns IIS 10.0 Detailed Error - 404.0 - Not Found.

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

回答1:

This change in Web.config solve my problem

 <handlers>
  <remove name="WebDAV"/>
  <remove name="OPTIONSVerbHandler"/>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="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" />
  <add name="OPTIONSVerbHandler" path="*" verb="OPTIONS" modules="ProtocolSupportModule" requireAccess="None" responseBufferLimit="4194304" />
</handlers>