跨域文件读取的问题
前端:前端网络请求 withCredentials 参数默认为 false,不会校验后端 Access-Control-Allow-Origin 配置。如果开启为 true,则会严格验证后端网络请求域名白名单,常见问题为文件下载跨域报错。
// create an axios instance
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
withCredentials: false, // send cookies when cross-domain requests
timeout: 15000 // request timeout
})
IIS:WebConfig
<!--设置服务器端允许跨域访问-->
<system.webServer>
<httpProtocol>
<customHeaders>
<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, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
浙公网安备 33010602011771号