IIS 10.0详细错误 - [httpDelete] [httpPut] 404.0

时间:2016-11-12 13:59:07

标签: asp.net-mvc httprequest

我试图在ASP.NET MVC中创建一个api。不幸的是我遇到两个HTTP请求有问题:DELETE和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";
    }

当我尝试发送DELETE或PUT然后浏览器返回IIS 10.0详细错误 - 404.0 - 未找到时,GET和POST请求工作正常。

<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 个答案:

答案 0 :(得分:4)

Web.config中的此更改解决了我的问题

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