【发布时间】:2018-02-08 05:14:09
【问题描述】:
我在理解为什么我得到“对预检请求的响应未通过访问控制检查:请求的资源上不存在'Access-Control-Allow-Origin'标头。来源”时遇到了一些大问题 所以为了更好地理解我的 webapi 项目有一个登录方法。该方法调用另一个 api(不同的服务器)进行登录以接收令牌。在客户端中,当我调用另一个项目时,我添加了标题(“Access-Control-Allow-Origin”,“”)。我还在 Azure 上启用了 cors。我什至在方法上方添加了 [EnableCors(origins:"",headers:"",methods:"",exposedHeaders:"*")]。
这是我的 webconfig 的一个高峰
<appSettings>
<add key="LogFilePath" value="c:\SAB.Hosting.WebApi.Log.Xml" />
<add key="LoginAddress" value="https://somewebsite/api/account/Login" />
<add key="GetToken" value="https://somewebsite/api/account/GetToken" />
<add key="RegisterAddress" value="https://somewebsite/api/account/Register" />
<add key="LogoutAddress" value="https://somewebsite/api/account/Logout" />
<add key="RegisterAddress" value="https://somewebsite/api/account/Register" />
<add key="owin:AutomaticAppStartup" value="false" />
</appSettings>
更新:我发现问题不是来自上面的链接。当我在我的 api 项目和我的 wcf 服务之间添加 SSL 证书时,就会发生这种情况。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="PersonService_HttpEndPoint" />
<binding name="SABService_HttpEndPoint" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="PersonService_TcpEndPoint">
<security mode="None" />
</binding>
<binding name="SABService_TcpEndPoint">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="CertBehavior">
<clientCredentials>
<clientCertificate x509FindType="FindByThumbprint" findValue="93F67C44F8RB0DC5FD1CA8013F256B8F84C8E08G" storeLocation="CurrentUser" storeName="My" />
<!--<clientCertificate findValue="PFX" x509FindType= "FindByExtension" />-->
</clientCredentials>
<callbackDebug includeExceptionDetailInFaults="True" />
</behavior>
</endpointBehaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<client>
<endpoint address="https://someaddress/SABService.svc" behaviorConfiguration="CertBehavior" binding="basicHttpBinding" bindingConfiguration="SABService_HttpEndPoint" contract="SABServiceReference.ISABService" name="SABService_HttpEndPoint" />
<endpoint address="https://someaddress/PersonService.svc" behaviorConfiguration="CertBehavior" binding="basicHttpBinding" bindingConfiguration="PersonService_HttpEndPoint" contract="PersonServiceReference.IPersonService" name="SABPersonService_HttpEndPoint" />
</client>
</system.serviceModel>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
我不知道为什么如果我添加 ssl 证书在登录时不会抛出 access-control-allow-origin。
等待您的解决方案。
谢谢你, 一个需要帮助的堕落程序员。
【问题讨论】: