zoukankan      html  css  js  c++  java
  • Asp.net Mvc、webApi配置允许跨域

    Web.config 下<system.webServer> 节点下配置

    <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="http://localhost:60699" />
            <add name="Access-Control-Allow-Headers" value="*" />
            <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
          </customHeaders>
        </httpProtocol>

    设置允许跨域传递Cookie

    <system.webServer>
        <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="http://localhost:8080" />
            <add name="Access-Control-Allow-Headers" value="content-type" />
            <add name="Access-Control-Allow-Methods" value="*" />
            <add name="Access-Control-Allow-Credentials" value="true"/>
          </customHeaders>
        </httpProtocol>
    
     </system.webServer>

    前端 请求的时候需设定:withCredentials = true; 设置了widthCredentials为true的请求中会包含远程域的所有cookie

  • 相关阅读:
    Asp:Cookies应用指南
    asp:cookies的属性
    数据库压缩
    asp之servervariables全部显示
    sql语句操作表
    asp之FSO大全
    SQL语句
    vbscript语句
    asp之vbscript函数
    IDEA 2017web项目的创建
  • 原文地址:https://www.cnblogs.com/tangchun/p/7878084.html
Copyright © 2011-2022 走看看