asp.net允许跨域配置web.config

<configuration>
<system.webServer>
    <modules>
      <add name="CultureAwareHttpModule" type="Web_SJWD.Lang.CultureAwareHttpModule" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
     <!---加下面这段可以跨域--->
    <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="*" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
      </customHeaders>
    </httpProtocol>


</system.webServer>
</configuration>

一直提示不能跨域,在web.config里加入上面这段后,就可以允许跨域访问了。

posted @ 2019-06-26 15:05  为乐而来  阅读(5113)  评论(0编辑  收藏  举报