zoukankan      html  css  js  c++  java
  • .net webapi项目跨域问题及解决方案

    问题:

    1.项目完成,部署到不同的iis版本上,跨域访问有的通有的不通

    解决办法:

    1.将复杂请求改为简单请求

    2.代码中去掉所有跨域设置,配置中添加或修改节点

    <system.webServer>
    <modules>
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <httpProtocol>
    <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Methods" value="POST,GET" />
    <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type,authorization,mypara,username" />
    </customHeaders>
    </httpProtocol>
    </system.webServer>

    <system.webServer>
    <modules>
    <remove name="FormsAuthentication" />
    <remove name="ApplicationInsightsWebTracking" />
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <httpProtocol>
    <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Methods" value="OPTIONS,GET,POST,PUT,DELETE" />
    <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type,authorization,mypara,username" />
    </customHeaders>
    </httpProtocol>
    </system.webServer>

    <system.webServer>
    <handlers>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <remove name="TRACEVerbHandler" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="HttpHealthCheck" path="health.check" type="ZJCX.WebAPI.HealthCheckHandler,ZJCX.WebAPI" verb="GET" />
    </handlers>
    <httpProtocol>
    <customHeaders>
    <add name="Access-Control-Allow-Origin" value="http://123.56.26.99:9052" />
    <add name="Access-Control-Allow-Credentials" value="true" />
    <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept,userid,corpid,errcode,errmsg" />
    <add name="Access-Control-Expose-Headers" value="errcode,errmsg" />
    </customHeaders>
    </httpProtocol>
    </system.webServer>

    架构师资料:加博主QQ:552343492

  • 相关阅读:
    IOS 获取时间的问题
    JQ 点赞
    截取字符串第一个空格前的字符
    JQ 的一些方法
    匿名函数var a =function(){}和function a(){}的区别
    完美支持中文编程的 Emacs 配置文件 .emacs
    linux find 命令忽略某个或多个子目录的方法
    Linux下如何用date设置时间
    nagios的监控代码!
    shell脚本监控apache进程数和oracle连接数
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/7759995.html
Copyright © 2011-2022 走看看