Access-Control-Allow-Credentials缺失

时间:2016-04-26 12:14:45

标签: c# asp.net-mvc azure asp.net-mvc-5 cors

我正在尝试从站点运行ajax调用,以及在Azure中托管的MVC 5应用程序。  但是,该调用必须具体为“withCredentials”参数。

 xhrFields: {
    withCredentials: true
 }

特定的参数浏览器返回错误'(在CORS标题“Access-Control-Allow-Credentials”中期待“true”'

要克服我已在Web.config中添加自定义标头。但Azure以某种方式删除它们期望,Test2标题存在于响应中。

我的webconfig

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <httpProtocol>
    <customHeaders>
      <add name="Test2" value="justTest" />
      <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
      <add name="Access-Control-Allow-Credentials" value="true" />
      <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE" />
    </customHeaders>
  </httpProtocol>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer></configuration>

我也试过特定的头文件arg。来自c#代码。

 HttpContext.Response.AddHeader("Access-Control-Allow-Credentials", "true");
 HttpContext.Response.AddHeader("Test", "true");

结果相同。删除了Cors标题。

如何将cors标题添加到响应中?

0 个答案:

没有答案