问题描述

.Net 应用部署到Azure App Service上后,出现5XX错误后,通过.Net Profiler Trace工具生成报告文件(HTML 加 JSON数据文件),在本地打开,遇见Access to XMLHttpRequest at 'file:///C:/Users/.../failedrequests.json' from origin 'null' has been blocked by CORS policy 问题

Access to XMLHttpRequest at 'file:///C:/Users/.../failedrequests.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome-untrusted, https, edge.

reportdata/failedrequests.json:1

Failed to load resource: net::ERR_FAILED

【Azure Developer】浏览器查看本地数据文件时遇见跨域问题(CORS)_chrome

怎么办?怎么办?

 

解决办法

网上寻找到答案,可以禁用浏览器本身的跨域校验来打开数据文件。关键点在于 “ --disable-web-security ” 参数。Edge 和 Chrome 都是一样。

## Edge 浏览器

msedge.exe  --disable-web-security --user-data-dir=<C:\Users\... 本地JSON文件/HTML文件夹路径>

 

## Chrome 浏览器

chrome.exe --disable-web-security --user-data-dir=<C:\Users\... 本地JSON文件/HTML文件夹路径>

 

具体操作步骤

1: 找到Edge 及 Chrome 软件的安装目录 ( msedge.exe  或 chrome.exe 文件所在之Floder)

【Azure Developer】浏览器查看本地数据文件时遇见跨域问题(CORS)_chrome_02

 

2:打开CMD窗口命令,执行--disable-web-security 指令

msedge.exe   --disable-web-security --user-data-dir=<....> 

## 或者

chrome.exe   --disable-web-security --user-data-dir=<....>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

 

3:  第二步执行后,自动打开浏览器窗口,在窗口中输入本地HTML文件地址,打开JSON文件成功。

【Azure Developer】浏览器查看本地数据文件时遇见跨域问题(CORS)_HTML_03

浏览器本地跨域校验问题解决!

 

参考资料

1) https://cloud.tencent.com/developer/article/1744377 

2) https://cloud.tencent.com/developer/article/2321850

 


当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!