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

  • 相关阅读:
    流浪西邮之寻找火石碎片
    给你一个666
    似魔鬼的步伐
    括号匹配2019
    挑剔程度
    到底有到少个小和尚?
    获取任务栏所有正在运行程序
    EXTJS4创建多级菜单
    关于时间的一些理解
    kof97调隐藏人物
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/7759995.html
Copyright © 2011-2022 走看看