仅限Chrome浏览器中的HTTP状态码405无效 [英] Invalid HTTP status code 405 in Chrome only

查看:216
本文介绍了仅限Chrome浏览器中的HTTP状态码405无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将客户保存到数据库的WCF服务,并且在Internet Explorer中按预期工作,但在Chrome中不是(因此,我将忽略HTML / JSON,因为它让我觉得这是一个web配置问题,但我可以发布,如果有人喜欢)。



在Chrome中,我收到错误:



无法加载资源:服务器响应状态为405(方法不允许)
Subscriber.htm:1 XMLHttpRequest无法加载 http://example.com/MyService.svc/SaveCustomer 。无效的HTTP状态码405



我的网页设定:

 <&的System.Web GT; 
<网页>
< namespaces>
< add namespace =System.Runtime.Serialization/>
< add namespace =System.ServiceModel/>
< add namespace =System.ServiceModel.Web/>
< /命名空间>
< / pages>
< /system.web>
< system.serviceModel>
< services>
< service name =IService.MyService>
< endpoint address =http://example.com/MyService.svc
binding =webHttpBinding
bindingConfiguration =
合约=IService
behaviorConfiguration =webHttpBinding/>
< / service>
< / services>
< client>
binding =webHttpBinding
bindingConfiguration =
address =http://example.com/MyService.svc
contract = IService/>
< / client>
<行为>
< serviceBehaviors>
<行为>
<! - 为避免公开元数据信息,请在部署前将下面的值设置为false并删除上面的元数据端点 - >
< serviceMetadata httpGetEnabled =true/>
<! - 要在调试中接收故障中的异常详细信息,请将下面的值设置为true。在部署前设置为false,以避免泄露异常信息 - >
< serviceDebug includeExceptionDetailInFaults =false/>
< /行为>
< / serviceBehaviors>
< endpointBehaviors>
< behavior name =webHttpBinding>
< webHttp />
< /行为>
< / endpointBehaviors>
< /行为>
< 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_64bitpath =*。 verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONSmodules =IsapiModulescriptProcessor =%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dllpreCondition =classicMode,runtimeVersionv4.0,bitness64responseBufferLimit =0/>
< add name =ExtensionlessUrlHandler-Integrated-4.0path =*。 verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONStype =System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0/>
< / handlers>
< httpProtocol>
< customHeaders>
<! - 启用跨域AJAX调用 - >
< add name =Access-Control-Allow-Originvalue =*/>
< / customHeaders>
< / httpProtocol>
< /system.webServer>

所以我阅读了一些文章并添加了相关部分,删除了WebDav,但似乎没有任何东西区别。

解决方案

对,我打算删除此主题,但认为有人可能会在将来遇到此问题并将其从在我的webconfig,我删除(否则你会收到一个错误)

 < httpProtocol> 
< customHeaders>
<! - 启用跨域AJAX调用 - >
< add name =Access-Control-Allow-Originvalue =*/>
< / customHeaders>
< / httpProtocol>

在我的WCF Web服务中,我添加了一个新的Global.asax并添加了

  Sub Application_BeginRequest(sender As Object,e As EventArgs)
HttpContext.Current.Response.AddHeader(Access-Control-Allow-Origin, *)
如果HttpContext.Current.Request.HttpMethod =OPTIONS则
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,接受)
HttpContext.Current.Response.AddHeader(Access-Control-Max-Age,1728000)
HttpContext.Current.Response.End()
End If
结束小组

希望这可以帮助


I have a WCF service which saves a customer to a database and works as expected in Internet Explorer but not in Chrome (for that reason i will leave out the HTML/Json as it makes me think this is a web config issue but i can post if anyone likes).

In Chrome i get the error:

Failed to load 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 Config:

<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've read a few articles and added relevant sections, removing WebDav but nothing seems to make a difference.

解决方案

Right, i was going to delete this thread but thought that someone may come across this issue in future and to save them from a headache.

In my webconfig, i removed (otherwise you get an error)

<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

这篇关于仅限Chrome浏览器中的HTTP状态码405无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆