.net 仅Chrome中的HTTP状态代码405无效

.net 仅Chrome中的HTTP状态代码405无效,.net,wcf,google-chrome,wcf-binding,.net,Wcf,Google Chrome,Wcf Binding,我有一个WCF服务,它可以将客户保存到数据库中,在Internet Explorer中按预期工作,但在Chrome中不按预期工作(因此,我将省略HTML/Json,因为它使我认为这是一个web配置问题,但如果有人喜欢,我可以发布) 在Chrome中,我得到一个错误: 加载资源失败:服务器响应状态为405(不允许使用方法) Subscriber.htm:1 XMLHttpRequest无法加载。无效的HTTP状态代码405 我的Web配置: <system.web> <c

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

在Chrome中,我得到一个错误:

加载资源失败:服务器响应状态为405(不允许使用方法) Subscriber.htm:1 XMLHttpRequest无法加载。无效的HTTP状态代码405

我的Web配置:

<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>


因此,我读了一些文章,并添加了相关部分,删除了WebDav,但似乎没有什么不同

是的,我本来打算删除这个帖子的,但我想将来可能会有人遇到这个问题,这样他们就不会头疼了

在我的网络配置中,我删除了(否则会出现错误)


希望这对我的ASP.NET MVC 5网站有帮助,因为其他解决方案都失败了

这是他在C#中的Global.asax函数

此链接可能会帮助您-
<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>
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
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();
}