背景:.net+swagger做的接口文档,
症状:之前一直好好的,突然出现了页面空白,什么内容也不显示,
浏览器脚本报错如下:
Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-jsSx+sDgVLmAmY6rvZIdJWHsvRzC7eqVVfLQR2IDv0k='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
解决方法:由于系统做过安全测试,为了解决一个低风险问题,在web.config中配置了
Content-Security-Policy 策略,取消该标头即可。
<add name="Content-Security-Policy" value="default-src 'self';" />
问题查找过程:
(1)检索.net swagger 空白,没有有意义的资料
(2)测试时发现,在ie浏览器中可以正常显示,在google 内核的,则显示空白
(3)检索上述控制台错误信息,暂未看到与swagger相关的,一般是说明增加一个 <meta>,配置同源策略之类的。本想按照帖子内容,增加一个 <meta>,后来想起,之前在IIS服务器中配置过一个同源策略,取消掉相关配置即可。