IIS 7.5 + enable PUT and DELETE for RESTFul servic

2019-01-04 18:57发布

i am trying to understand how IIS 7.5 handles POST and PUT request.

I am writing a RESTful service using OpenRasta framework. The POST operation works without any problem, but the PUT operation for the same URL does not. It returns error like the following

Detailed Error Information
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002

the url is like this following "http://localhost/MyService/Resource.Something.manifest"

Same setup works fine in visual studio development IIS.

Solution

Basically the default ExtensionlessUrlHandler does not accept PUT and DELETE verb. Just need to add them.

<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />

13条回答
倾城 Initia
2楼-- · 2019-01-04 19:17

in the web.config

<system.webServer>
    <handlers>
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>

you can also use the IIS management UI and define this globally, or default web server

查看更多
混吃等死
3楼-- · 2019-01-04 19:19

What worked for me was uninstalling WebDav completely.

查看更多
The star\"
4楼-- · 2019-01-04 19:20

In windows server 2012. Open applicationHost.config file in notepad with Administrator rights

applicationHost.config file is found in C:\Windows\System32\inetsrv\config

Locate the section

 <verbs allowUnlisted="false" applyToWebDAV="true">
   <add verb="GET" allowed="true" />
   <add verb="HEAD" allowed="true" />
   <add verb="POST" allowed="true" />
   <add verb="DELETE" allowed="false" />
   <add verb="TRACE" allowed="false" />
   <add verb="PUT" allowed="false" />
   <add verb="OPTIONS" allowed="false" />
</verbs>

Notice DELETE and PUT HTTP Verbs are set to false. Change them to true.

It should now read as below

 <verbs allowUnlisted="false" applyToWebDAV="true">
   <add verb="GET" allowed="true" />
   <add verb="HEAD" allowed="true" />
   <add verb="POST" allowed="true" />
   <add verb="DELETE" allowed="true" />
   <add verb="TRACE" allowed="false" />
   <add verb="PUT" allowed="true" />
   <add verb="OPTIONS" allowed="false" />
</verbs>

Save the file. You have enabled HttpPut and HttpDelete requests on your web server

查看更多
戒情不戒烟
5楼-- · 2019-01-04 19:26

I tried in IIS 8.

  • **uninstall WebDav Publishing

    Steps to uninstall -> Control Panel -> Go to Programs and features -> Turn windows featues on or off-> Select Internet Information Services->World Wide Web Services->Common HTTP Featues->"Remove" WebDAV Publishing by unchecking WebDAV option**

查看更多
Juvenile、少年°
6楼-- · 2019-01-04 19:29

For me this does the trick in the web.config.

<system.webserver>
    <handlers>
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="IsapiModule" scriptProcessor="c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />

          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
<system.webserver/>

<system.web>
  <authentication mode="Windows" />
  <identity impersonate="true"/>
<system.web/>

I used following configuration:

  • IIS 7.5
  • Windows Server 2008 R2
  • Custom Application Pool, .NET 4.0, Integrated
  • Windows Authentication = true
  • Anonymous Authentication = false

Hope it helps. ;-)

查看更多
别忘想泡老子
7楼-- · 2019-01-04 19:29

Reason for 500 error !

Hi all,

I want to post my own research too, I hope it would help future enthusiasts. As suggested in answers, I can't uninstall WebDav so I have added the line below in web config (from other answers)

 <system.webServer>
    <handlers>
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>

but I got a 500 error, when I have enabled debug mode found this

 Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'ExtensionlessUrlHandler-Integrated-4.0'

Answer

Its because there was already an ExtensionlessUrlHandler in the handler mappings section, do the following to resolve the issue.

Method 1

1) Go to Your IIS Manager and select your app

2) Go to Handler Mappings feature

3) Find ExtensionlessUrlHandler-Integrated-4.0 and delete it.

4) Add ExtensionlessUrlHandler in your webconfig (as mentioned in above answers)

<system.webServer>
<handlers>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

Method 2

1) Remove ExtensionlessUrl handler from your web config

2) Click on your app in IIS Server, go to HandlerMappings

3) Find ExtensionlessUrlHandler-Integrated-4.0 (only this name, ignore others)

4) right click on it and choose Edit

edit handler

5) click on 'Request Restrictions' and select Verbs tab & choose All Verbs

this will enable extensionsless handler to allow all verbs.

I will go with method 1, as we can have control in web.config. But make sure you check the deployment server for duplicate handler definitions.

查看更多
登录 后发表回答