• .net mvcwebapi设置允许跨域


     
    global.asax中
    //解决跨域问题 protected void Application_BeginRequest(object sender, EventArgs e) { //RegisterRoutes(RouteTable.Routes); if (HttpContext.Current.Request.HttpMethod == "OPTIONS") { HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept"); HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000"); HttpContext.Current.Response.End(); } else { HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
    HttpContext.Current.Response.AddHeader(
    "Access-Control-Allow-Methods", "GET, POST,PUT, DELETE"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type"); } }

    web.config中

      <!--解决跨域问题-->
        <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Max-Age" value="30" />
            <add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />
            <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
          </customHeaders>
        </httpProtocol>

    iis

    网站的应用程序池 管道模式必须是经典模式 ,否则不行

  • 相关阅读:
    这是一棵树吗
    感染者
    es6 语法
    css3 flex 详解,可以实现div内容水平垂直居中
    移动端实现复制内容至剪贴板小例子
    jq+mui 阻止事件冒泡
    移动端H5 判断IOS还是Android 平台
    移动端布局 rem,和px
    关于H5移动端开发 iPhone X适配
    H5 微信公众号 监听返回事件
  • 原文地址:https://www.cnblogs.com/jiamengyang/p/10939571.html
Copyright © 2020-2023  润新知