简体   繁体   中英

ASP.NET 5 Accept Verbs for Web API

I've had issues getting HTTP Delete and Put to work with ASP.NET 5 (vNext). Running calls to api endpoint with Delete and Put verb has resulted into a 404 error from IIS Express.

In previous version of ASP.NET you enabled this by accepting additional verbs in web.config.

I've figured out that changing the applicationhost.config under ./vs/config folder can enable the delete and put verbs but there must be another way enabling these from Visual Studio or by some config in the new project type that comes with ASP.NET 5.

Where can I configure this in ASP.NET 5? hosting.ini or project.json? Somewhere else?

web.config is still a thing but it only used for IIS configuration and is not needed by your app itself but may be needed if your app runs in IIS.

so you should be able to run your app from the command line using

dnx web 

in the root folder of your web app project and I would expect that you find it works there.

for IIS you still need web.config and if you create a new asp.net 5 web project in VS 2015 using the latest web tooling for beta7 it will/should put a web.config file in your wwwroot folder.

this article may also help you

You need to install HTTPPlatformHandler on your IIS http://docs.asp.net/en/latest/publishing/iis.html then your web.config should look like this:

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

If you have WebDAV handler installed on IIS, delete it or remove it in your web.config as it take over the PUT and DELETE verbs.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM