「プリフライトリクエストに対する応答がアクセスコントロールのチェックを通過しない理由を理解することに大きな問題があります:いいえ 'Access-Control-Allow-Origin'ヘッダーOrigin " 私のwebapiプロジェクトの理解を深めるために、ログインの方法があります。このメソッドは、別のapi(別のサーバー)を呼び出してトークンを受信します。クライアントでは、他のプロジェクトに電話をかけるときにヘッダー( "Access-Control-Allow-Origin"、 "")を追加します。私はAzureのcorsも有効にしました。私はメソッド[EnableCors(起源: ""、ヘッダ: ""、メソッド: ""、exposedHeaders: "*")の上にメソッドを追加しました。WCFプロジェクト内から別のWCFプロジェクトへのApiコールのエラー
これは
<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>
アップデート私のWebConfigのピークである:私は、問題は、私は私のAPIプロジェクトと私のWCFサービス間のSSL証明書を追加するときabove.Thisが起こっているリンクからのものではないことが分かりました。
<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証明書を追加すると、ログイン時にアクセス制御許可元がスローされない理由がわかりません。
解決策を待っています。
ありがとう、 苦労しているプログラマ。
まあ、私はMVCを使用していない、私はWebConfigのを使用しています。これはwebconfigでも追加できますか? – user2964720
@ user2964720 AFAIKはweb.configを使用して静的ヘッダーを各応答に追加することができます。この質問を参照してください - https://stackoverflow.com/questions/29970793/enabling-cors-through-web-config-vs-webapiconfig-and-controller-attributes –
@ user2964720ところで、このソリューションはMVCプロジェクト。これは、OWINによってホストされているすべてのWebアプリケーションにも使用できます。 –