【问题标题】:Refused to load stylesheets because it violates Content Security Policies拒绝加载样式表,因为它违反了内容安全策略
【发布时间】:2020-03-08 12:25:12
【问题描述】:

我正在尝试将 jquery 和 css 文件添加到我的 .cshtml 文件中,但出现内容安全策略错误。

我已经尝试添加<meta http-equiv="Content-Security-Policy" content="default-src 'self' *.aspnetcdn.com/"> 之类的东西,但它不起作用。

Here are the errors that I am getting

这是 .cshtml 文件:

@using Genesis.SharedLibrary.ViewModels.Genesis.ALG

@inject Genesis.Application.Services.Commons.IGenericServices _genericServices;
@{
    var staticFileVersion = _genericServices.GetAppSettingValue("OtherSettings", "StaticFileVersion");
}


@model List<TravelRequestAdminViewModel>

<body>
    @* DATA TABLE WITH SEVEN COLUMNS AND MANY ROWS *@
</body>


<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css" />

<script type="text/javascript" src="~/lib/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>

<script src="~/shared/js/Views/travelRequestAdminScript.js?v=@staticFileVersion"></script>

【问题讨论】:

标签: javascript c# html css ajax


【解决方案1】:

您需要放宽远程脚本的默认策略

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://code.jquery.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; script-src 'self' https://example.com/ 'unsafe-inline' 'unsafe-eval';  media-src *">

参考:

https://developer.chrome.com/extensions/contentSecurityPolicy#relaxing

【讨论】:

  • 您阅读参考资料了吗?您尝试从中获取文件的不同域的所有内容都在其中
猜你喜欢
  • 2017-11-26
  • 2015-09-21
  • 1970-01-01
  • 2013-07-19
  • 1970-01-01
  • 2015-09-26
  • 1970-01-01
  • 2020-06-23
相关资源
最近更新 更多