本帖最后由 sunnyboom 于 2020-6-19 11:42 编辑
问题描述:浏览器跨域问题 做过的尝试:修改asp.net项目下的web.config文件,在<system.webServer>增加了以下代码: - <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Origin" value="localhost:8080/TestWeb" />
- <add name="Access-Control-Allow-Headers" value="Access-Control-Allow-Headers, Origin,Accept,Expires, X-Requested-With,Cache-Control,Content-Type,Pragma,Access-Control-Request-Method, Access-Control-Request-Headers" />
- <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
- <add name="Access-Control-Allow-Credentials" value="true" />
- </customHeaders>
- </httpProtocol>
复制代码
该办法的处理结果:Access-Control-Allow-Origin标签值“配置具体的IP或域名时”跨域问题是可以被解决的 产生的新问题(目前需要解决的问题):因为我现在有一个域名和一个IP需要能够同时访问报表服务,但是上面所示标红的代码不能配置“*”,如下图所示。 - Access to fetch at 'http://localhost:58720/api/reporting/reports/AcmeStore.rdlx/info' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
复制代码
现在我需要怎么做能够让多个IP同时支持跨域访问;下面是我使用的web测试程序,asp.net为咱们示例程序中的“ActiveReportsV14SP1\示例源码\WebSamples14-master\JsViewerSamples\JSViewer_MVC”,您可以跑起来测试一下。 - <?xml version="1.0" encoding="utf-8"?>
- <!--
- For more information on how to configure your ASP.NET application, please visit
- http://go.microsoft.com/fwlink/?LinkId=301880
- -->
- <configuration>
- <appSettings>
- <add key="webpages:Version" value="3.0.0.0"/>
- <add key="webpages:Enabled" value="false"/>
- <add key="ClientValidationEnabled" value="true"/>
- <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
- </appSettings>
- <system.web>
- <compilation debug="true" targetFramework="4.5"/>
- <httpRuntime targetFramework="4.5" requestPathInvalidCharacters=""/>
- </system.web>
- <system.webServer>
- <handlers>
- <add name="nostaticfile" path="*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
- </handlers>
- <security>
- <requestFiltering allowDoubleEscaping="true"/>
- </security>
- <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Origin" value="*" />
- <add name="Access-Control-Allow-Headers" value="Access-Control-Allow-Headers, Origin,Accept,Expires, X-Requested-With,Cache-Control,Content-Type,Pragma,Access-Control-Request-Method, Access-Control-Request-Headers" />
- <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
- <add name="Access-Control-Allow-Credentials" value="true" />
- </customHeaders>
- </httpProtocol>
- </system.webServer>
- </configuration>
复制代码
|