青菜仟

您现在的位置是:综合资讯>程序解决方案

综合资讯

C#.net 设置Access-Control-Allow-Origin来实现跨域

2020-02-14 程序解决方案 62
青菜仟推荐说:C#.net 设置Access-Control-Allow-Origin来实现跨域.C#.net 设置Access-Control-Allow-Origin来实现跨域.

  <system.webServer>
      
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET" />
        <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type" />
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

 

 

或者在Action或Action过滤器里设置

            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Response.Headers.Add("Access-Control-Allow-Methods", "POST");
            Response.Headers.Add("Access-Control-Allow-Headers", "x-requested-with,content-type");