Ali RAN
Ali RAN

Reputation: 563

delete method from localhost works fine but from IIS does not work-web api

I'm trying to Delete an object from database; I have an UI layer and a Service layer, I have loaded the UI and the Service separately on IIS.I am using asp.net web api and i send the request with http delete method.So when i run services(with f5)and send the delete request to http:// localhost:15957/ all thing is ok. But when i send the request to the site that host in iis get this error:

HTTP Error 405.0 - Method Not Allowed

I look at the response header and and see the unexpected header:

Allow:GET, HEAD, OPTIONS, TRACE

I dont add this header.

On the Web.config of the Service layer I'm adding the following to the header for CORS:

<customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type, x-xsrf-token" />
        <add name="Access-Control-Allow-Methods" value="PUT, GET, POST, DELETE" />
</customHeaders>

What is my problem?

Upvotes: 2

Views: 2601

Answers (2)

Code Uniquely
Code Uniquely

Reputation: 6373

Update the IIS web.config file to allow all the that you need. Just check that the required ones are specified.

<system.webServer>
    <handlers>
        <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"/>
    </handlers>
</system.webServer>

Upvotes: 2

Simon Holman
Simon Holman

Reputation: 150

The Handler mapping in IIS is probably only set to allow GET, HEAD, OPTIONS, TRACE by default.

You need to go to IIS, go into the Handler Mappings for the site (It will probably be one of the ones starting with ExtensionlessURLHandler....), right click then edit, then click on the Request Restrictions button and go to the Verbs tab. You can then add the additional verbs you need, or select All Verbs.

You should also be able to configure this in your web.config but I've always done it in IIS.

Upvotes: 1

Related Questions