Invalid HTTP Status Code 405 Only in Chrome

I have a WCF service that saves the client to the database, and it works as expected in Internet Explorer , but not in Chrome (for this reason I will not leave HTML / Json, as this makes me think that this is a web configuration problem but I can post it if someone likes).

In Chrome, I get an error:

Failed to load the resource: the server responded with a status of 405 (method not allowed) Subscriber.htm: 1 XMLHttpRequest cannot load http://example.com/MyService.svc/SaveCustomer . Invalid HTTP Status Code 405

My web configuration:

<system.web> <compilation debug="false" strict="false" explicit="true" targetFramework="4.0" /> <pages> <namespaces> <add namespace="System.Runtime.Serialization" /> <add namespace="System.ServiceModel" /> <add namespace="System.ServiceModel.Web" /> </namespaces> </pages> </system.web> <system.serviceModel> <services> <service name="IService.MyService"> <endpoint address="http://example.com/MyService.svc" binding="webHttpBinding" bindingConfiguration="" contract="IService" behaviorConfiguration="webHttpBinding" /> </service> </services> <client> <endpoint binding="webHttpBinding" bindingConfiguration="" address="http://example.com/MyService.svc" contract="IService" /> </client> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="webHttpBinding"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="false" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <remove name="WebDAVModule" /> </modules> <handlers> <remove name="WebDAV" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.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" 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> <httpProtocol> <customHeaders> <!-- Enable Cross Domain AJAX calls --> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Content-Type, Authorization, Accept, X-Requested-With" /> <add name="Access-Control-Allow-Methods" value="OPTIONS, TRACE, GET, HEAD, POST, PUT" /> </customHeaders> </httpProtocol> </system.webServer> 

So, I read several articles and added the appropriate sections, removing WebDav, but nothing seems to have changed.

+5
source share
2 answers

That's right, I was going to remove this thread, but thought that someone might run into this problem in the future and save them from a headache.

In my webconfig, I am deleted (otherwise you will receive an error message)

 <httpProtocol> <customHeaders> <!-- Enable Cross Domain AJAX calls --> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Content-Type, Authorization, Accept, X-Requested-With" /> <add name="Access-Control-Allow-Methods" value="OPTIONS, TRACE, GET, HEAD, POST, PUT" /> </customHeaders> </httpProtocol> 

In my WCF web service, I added a new Global.asax and added

 Sub Application_BeginRequest(sender As Object, e As EventArgs) HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*") If HttpContext.Current.Request.HttpMethod = "OPTIONS" Then HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache") HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST") HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept") HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000") HttpContext.Current.Response.End() End If End Sub 

Hope this helps

+13
source

The computer response worked on my ASP.NET MVC 5 site where other solutions failed.

Here is its Global.asax function in C #.

 protected void Application_BeginRequest(object sender, EventArgs e) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (HttpContext.Current.Request.HttpMethod != "OPTIONS") return; HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept"); HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000"); HttpContext.Current.Response.End(); } 
+3
source

All Articles