How to allow a DELETE method with IIS Express and Web API? - asp.net-web-api

I am trying to send a delete request to my Web API service via Fiddler and am getting back a 405 "Method not allowed" error.
I have read extensively about removing the "WebDAV" module in web.config and similar suggestions (WebDAV is not enabled in my applicationhost.config anyway), but nothing I have tried has worked.
My service is currently running on IIS Express 10 (launching from Visual Studio). I do have this in my web.config file:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"/>
I would have thought the verb="*" piece would have allowed DELETE, but it does not seem to work.
One other note - when I inspect the response in Fiddler, under the Security heading it says: Allow: GET, POST.
I am not sure where that "Allow" parameter is being set (I am new to Web API).
Any help would be greatly appreciated. Please let me know what other information you need from me and I will add it.
Thank you!

Just reproduced this by creating a new webapi project [targeting .net framework 4.7.1]
Through Fiddler, I can hit the DELETE endpoint without any changes to web.config.
Please make sure to use correct endpoint including the id parameter.
e.g http:localhost:xxxx/api/values/id // please include the id and xxxx is port number.
If http:localhost:xxxx/api/values is used without id , I get the same result 405 Method Not Allowed
Hope this helps.

You can modify the IIS Express applicationHost.config in the %userprofile%\documents\IISExpress\config folder.  To enable PUT and DELETE for extensionless Urls scroll down to the bottom of the IIS Express applicationHost.config file and look for a handler entry that starts with: <add name="ExtensionlessUrl-Integrated-4.0".... In the "verb" attribute add PUT and DELETE so the "verb" attribute looks like:  verb="GET,HEAD,POST,DEBUG,PUT,DELETE"

Update your web config like this
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/> <!-- ADD THIS -->
</modules>

Related

Laravel Azure App Service Delete Method Not Allowed

Hosting a laravel app in Azure's App Service and every time the web application makes DELETE requests, it throws up 405 Method Not Allowed and returns the message below:
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
I've exhausted all options I could find in the internet and tried all stuff mentioned. Hope someone could help.
If your application uses .NET WebAPI, you may get a 405 Method Not Allowed error when you issue a PUT or DELETE request.
This error is caused because the WebDAV module intercepted the request
In your web.config, try to insert this code
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
And this issue duplicate of this question

Strange Configuration Error in web.config

I am getting the following error in my WebApi application:
An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: Unrecognized attribute 'MaxCachedResults'. Note that attribute names are case-sensitive.
This is my roleManager entry in web.config and as you can see I am not specifying the MaxCachedResults attribute, although I did add this initially, I removed it so it's no longer being used and I'm not sure where it's picking this up from.
<roleManager enabled="true" defaultProvider="MyRoleProvider" cacheRolesInCookie="false">
<providers>
<clear />
<add name="MyRoleProvider" type="SiteWorksAPI.RoleProviders.MyRoleProvider, SiteWorksAPI" connectionStringName="SiteWorks" applicationName="/" />
</providers>
</roleManager>
The error happens when I call var resp = await _httpClient.GetAsync(resourceUri) and inspecting resp.Content.ReadAsStringAsync().Result displays a 'Configuration Error' HTML page with the above error message.
I have tried all of the following with any success:
Rebooted my PC
Recycled the application pools
Restarted IIS
Cleared down the Tempoary ASP.NET directory
Does anyone know what's going on here?
It seems that Castle Windsor was caching an older copy of the web.config file. After changing the caching options on the WebRequestHandler I was able to get the HttpClient to pick up the new web.config file.

elfinder with MVC 3 and IIS 7

Im trying to use elfinder in my MVC 3 application and using this .NET connector
: http://elfinderconnectornet.codeplex.com/ for elfinder. And this connector works with http handler configured in section in WebConfig. For example:
for url like :
192.168.0.17:9002/elfinder.connector?_=1347370006351&cmd=open&target=&init=true&tree=......
i have a handler in web config
<system.web>
<httpHandlers>
<add verb="*" path="elfinder.connector" type="ElFinder.Connector.Connector" />
</httpHandlers>
</system.web>
and in global.asax.cs routes.IgnoreRoute("elfinder.connector");to ignore this url in "Controller/Action" routing.
When im running this code in VisualStudio localhost all works fine but on IIS 7 i have an 404 error.
May be IIS have custom config for httphandlers? some checkbox need to be checked :)
Any idea?
I received the same error because I didn't have read permissions on the directory. You must give, at least, read permission to see the folders and files.
Hope it helps. Regards.

Custom Image Handler

I've got a custom image handler (.ashx) which extends IHttpHandler. Basically all it does is fetch some images from a database and make them a thumbnail if requested.
This works fine on my local machine, but when I deploy it to my IIS 6 web server my images don't display.
My question is - can anyone tell me what the procedure is for setting up a handler like this in IIS 6?
Update
The paths to my image (that don't display) look like this:
http://xxx.xx.xxx.xxx/Helpers/ImageHandler.ashx?imageid=7&thumbnail=1
I've added this to my web.config file, but still no luck:
<httpHandlers> <add verb="*.png" path="MyWeb.Helpers.ImageHandler" type="MyWeb.Helpers.ImageHandler, MyWeb"/> </httpHandlers>
Thanks.
You need configure IIS6 to map the mime types to be parsed by .NET, so that they can be called by your handler; there is more on this here.
EDIT
Also try adding this to your web.config;
<add verb="*" path="*.png" type="MyWeb.Helpers.ImageHandler, MyWeb.Helpers"/>
Hope this helps,
Matt

Routing requests that end in ".cshtml" to a controller

(This is cross-posted to the ASP.NET forms)
I'm working on the WebGit .NET project, and we are close to a "1.0" release. However, I'm having trouble getting my "Browse" controller (which pulls files out of the repository) to serve-up ".cshtml" files.
I originally had trouble with ".config" and ".cs" files as well, but I fixed that with this in the web.config:
<location path="browse">
<system.webServer>
<security>
<requestFiltering>
<fileExtensions allowUnlisted="true">
<clear />
</fileExtensions>
<hiddenSegments>
<clear />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</location>
The routing that should be handling this request (that is successfully routing everything else) is:
routes.MapRoute(
"View Blob",
"browse/{repo}/blob/{object}/{*path}",
new { controller = "Browse", action = "ViewBlob", path = UrlParameter.Optional });
Now, whenever I try to access a URL that ends in ".cshtml", it gives a 404, even though my request should have been handled by the "Browse" controller. The files I'm serving-up do not exist on disk, but are instead pulled from a git repository as blobs. Every other file extension that I have tried works just fine.
How can I fix this behavior?
EDIT: I have tried disabling WebPages like so:
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
But that appears to have no effect.
As a quick workaround, you can put a temporary browse.cshtml file at your application root and put this inside your web.config,
add key="webpages:Enabled" value="false"
This is a known bug in ASP.NET WebPages, which gets implicitly loaded when you are using MVC 3. I don't think there is a straightforward way of disabling this behavior. The only workaround is to use a different extension (specifically, one that is not listed via WebPageHttpHandler.GetRegisteredExtensions())
This will be fixed in MVC 4, however. Sorry for the inconvenience.

Resources