ASP.NET 5 接受 Web 动词 API

ASP.NET 5 Accept Verbs for Web API

我在使用 ASP.NET 5 (vNext) 时遇到了 HTTP Delete and Put 问题。 运行 使用 Delete 和 Put 动词调用 api 端点导致 IIS Express 出现 404 错误。

在以前的 ASP.NET 版本中,您通过在 web.config 中接受额外的动词来启用此功能。

我发现更改 ./vs/config 文件夹下的 applicationhost.config 可以启用删除和放置动词,但必须有另一种方法从 Visual Studio 或某些人启用这些在ASP.NET 5.

自带的新工程类型中配置

在 ASP.NET5 中我可以在哪里配置它? hosting.ini 还是 project.json?其他地方?

web.config 仍然存在,但它仅用于 IIS 配置,您的应用程序本身不需要它,但如果您的应用程序 运行s 在 IIS 中,则可能需要它。

因此您应该能够使用

从命令行运行您的应用程序
dnx web 

在您的 Web 应用程序项目的根文件夹中,我希望您会发现它在那里工作。

对于 IIS,您仍然需要 web.config,如果您使用最新的 beta7 网络工具在 VS 2015 中创建一个新的 asp.net 5 网络项目,它 will/should 放置一个 web.config 文件在您的 wwwroot 文件夹中。

this article也可能对你有帮助

您需要在 IIS 上安装 HTTPPlatformHandler http://docs.asp.net/en/latest/publishing/iis.html 然后您的 web.config 应该如下所示:

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
  </system.webServer>
</configuration>

如果您在 IIS 上安装了 WebDAV 处理程序,请删除它或在您的 web.config 中删除它,因为它接管了 PUT 和 DELETE 动词。

<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"> 
      <remove name="WebDAVModule"/> 
    </modules> 
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
  </system.webServer>
</configuration>