I'm working with C# Web Api and AngularJs. If I add
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
The delete request works from fiddler, but when it comes to call it from angularJs i got an error that Options is not define. The options call is done by default by angular.
If I don't add the code form above the HttpDelete does not work. I got a response header like:
Allow: GET, HEAD, OPTIONS, TRACE
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
I am using $resource to call the web api from AngularJS. The web.config from web api with removed webDavModule looks like:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="TRACEVerbHandler" />
<remove name="WebDAV"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With, accept, content-type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
The request on google chrome looks like: this
Do you have any idea why I've got this issue?
It seems to be you are hosting your AngularJs application on localhost:<port>. Your Web Api must respond with Access-Allow-Control-Origin containing your localhost:<port>.
When you are hosting on different port your browser sends a pre-flight request with HTTP OPTIONS. Web API must allow HTTP OPTIONS verb as well.
http://www.html5rocks.com/en/tutorials/cors/
You can also look inside of Chrome Developer Tools console. Chrome must write an error message in this case to a console. It answers to you HTTP 405 it means OPTIONS HTTP Verb is not allowed, despite it is in response Access-Control-Allow-Headers headers. IIS adds HTTP headers but HTTP 405 comes from your services.
For example, in my OAuth/JWT service implementation I had needed to write logic to respond HTTP 200 on OPTIONS verb on dev environment because of strange constellation of Chrome + localhost:<port> and preflight requests.
Related
I have an Azure API app service.
I have added * to CORS settings within it.
I have another web app in Azure where I make calls to Azure API app.
Example : https://XXXXXX.XXXXXX.net/api/XXXXXX
The calls work when the api is working with small video files but whenever a video is more than 20mb, I always get -
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:9000' is therefore not allowed access.
The response had HTTP status code 500
The API accepts an ID from the POST request and works with videos in a folder in Azure Media storage. This error doesn't happen when the video is under 20mb.
Any idea what the problem could be ?
I keep getting
500 - The request timed out.
The web server failed to respond within the specified time.
as Response and the CORS error on console.
The API call works and does its stuff though.
Here is the web.config looks like
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" maxRequestLength="5097151" executionTimeout="1800" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="5097151000"/>
</requestFiltering>
</security>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<httpProtocol>
</httpProtocol>
</system.webServer>
There's no CORS header coming back because the response is HTTP 500, most probably due to the payload exceeding the maximum size allowed.
Amend your web.config with a larger value:
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="{value In Bytes}"/>
</requestFiltering>
</security>
</system.webServer>
</configuration>
From MSDN (emphasis mine) —
maxAllowedContentLength
Optional uint attribute.
Specifies the maximum length of content in a request, in bytes.
The default value is 30000000, which is approximately 28.6MB.
If there's no CORS header coming back and the CORS setting is set, then probably the application is crashing due to an exception, and it's too big to be deserialized. That was my issue.
Try debugging it with the azure cli.
I have got a new iis server and from a while i am finding solution for error :
405 - HTTP verb used to access this page is not allowed. The page you
are looking for cannot be displayed because an invalid method (HTTP
verb) was used to attempt access.
I have seen below solutions:
1.
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
2. IIS Settings http://www.somacon.com/p126.php
Solution 1, causes Internal server error and later unable to find the solution.
Solution 2, i am unable to find Property window in iis 8.5, so unable to try the same.
Please help
I also had the same internal server error when attempting the first solution, described at HTTP 405 error with Web API. Since I wasn't even using WebDAV, I opted to remove it entirely from IIS (see screenshot below). After a required server restart, the problem was resolved.
One of my colleague helped me out. I was missing some of the major iis features.
Goto Add Roles and Features Wizard, then Web Server (IIS)> Web Server > Application Development > Select ASP.net 3.5 and Asp.net 4.5 and click Install.
Goto cmd prompt and iisreset.
For WCF service, Kindly check Http Activation under WCF Services.
Hope this may help you and save your time.
This is late but may help some other guys.
My application is WEB-API dotnet Core face same problem when deploy on local server resolve this by doing following steps.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
<!-- add this -->
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="TRACEVerbHandler" />
<remove name="OPTIONSVerbHandler" />
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="aspNetCore" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" 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" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<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" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
</handlers>
I have faced the same issue with with my PHP application that runs on "Windows server 2019" and IIS server. I tried to test my FHIR APIs through Postman but only POST and GET request were working fine. But PUT requests were not working. Any solutions that were suggested to do on web.config file were not worked for me.
Only solution was to remove "WebDAV" module from IIS (as suggested by Mark G). Restarting the server machine is a MUST to apply that feature removal and make my application to work properly.
I am trying to create HttpDeleteservice in my Web Api but its not working and giving me the follwoing error
Handler "WebDAV" has a bad module "WebDAVModule" in its module list
My service code implemented as follows
[HttpDelete]
public string DeleteItem(long itemId)
{
try
{
// Implementation goes here
}
catch (Exception ex)
{
throw ex;
}
}
I am using the following http request using Postman plugin using HTTPDelete method
http://localhost:85/RM.Services/api/Item/DeleteItem?itemId=12
I used the following configuration to solve this issue at web.config
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
also trying the following settings in web.config
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
but nothing work for me the same error appears
I tried to remove WebDav from IIS with the following steps
go to Control Panel then Programs and Fetures then Turn windows features on or off
then Internet Information Services then World Wide Web Services then Common HTTP Features
then remove WebDav Features
In this case i recieved 404 error
Any help in this issue?
In Web API you shouldn't put action DeleteItem in your URL, here the routing is different from MVC. You should call using HTTPDelete method and use this url:
http://localhost:85/RM.Services/api/Item/12
i removed the following configuration from Web.config
<modules>
<remove name="WebDAVModule" />
</modules>`
and keep
<handlers>
<remove name="WebDAV" />
</handlers>
and now everything is working fine
I'm trying to deploy a WebAPI project to Azure.
It works locally. When I Publish it to Azure, I get 404 on the controller routes.
Looking at the logs, I see the routes are being handled as static files, instead of going through my controllers.
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://xxxxx:80/api/studies
Physical Path D:\home\site\wwwroot\api\studies
Logon Method Anonymous
Logon User Anonymous
My Global.asax is:
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
And my WebApiConfig.Register is:
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
I've looked at similar questions and tried tweaking my Web.config to no avail. It currently looks like this (relevant part only):
<system.webServer>
<httpErrors existingResponse="PassThrough"/>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
By the way, I'm on Entity Framework 6 and not using MVC, just straight up WebAPI.
Somehow my Global.asax got excluded from the project, so the route mapping never happened.
I had the same issue. nothing else worked until changing my web config to look like this solved it for me
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Have you checked all the necessary Windows Features for your server? Maybe some features are missing from IIS, for example:
Internet Information Services - World Wide Web Services - Application Development Features - ASP.NET.
You can find and check which features are installed on your machine by going to Windows Features (or going through the Server Manager if you're on a Windows Server).
If that is not your problem, it can sometimes be that ASP.NET is not installed properly. You can re-install ASP.NET by following this article: http://support.microsoft.com/kb/2736284 (it depends on your operating system).
I have a web application which talks to a local service (also mine) and produces results from the RESTful calls.
I have deployed the web application through IIS 7 on my system.
So far it looks fine, except that I am not able to perform POST operations, they just seem like NOP's.
Although, when I install VS 2012 on the machine the POST operations start working. I am not sure what exact thing the VS 2012 install sets which causes the POST operations to work.
Any hints?
You have to enable POST operations in your web.config file. A simple implementation is demonstrated below
<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>
Make sure to inlcude this in your config file:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>