Chrome 和 Safari 错误::不允许加载本地资源:file:///D:/CSS/Style.css

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5074680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:45:58  来源:igfitidea点击:

Chrome & Safari Error::Not allowed to load local resource: file:///D:/CSS/Style.css

cssgoogle-chromesafari

提问by Maybe2013

When I access my aspx page in chrome or safari it shows this error in console

当我在 chrome 或 safari 中访问我的 aspx 页面时,它在控制台中显示此错误

Not allowed to load local resource: file:///D:/CSS/Style.css

不允许加载本地资源:file:///D:/CSS/Style.css

Everything works fine in IE and FF.

在 IE 和 FF 中一切正常。

I use an external CSS which is linked in aspx page via

我使用一个外部 CSS,它通过在 aspx 页面中链接

<link rel="stylesheet" media="all" href="file:///D:/CSS/Style.css" type="text/css" />

I have tried all the combination of "/" & "\" slashes..

我已经尝试了“/”和“\”斜线的所有组合..

Whether I am giving file path in wrong manner or its any security exception in these browsers(I am logged in as administrator)... What am I doing wrong?

我是否以错误的方式提供文件路径或在这些浏览器中出现任何安全异常(我以管理员身份登录)......我做错了什么?

回答by Zinc

You wont be able to access a local resource from your aspx page (web server). Have you tried a relative path from your aspx page to your css file like so...

您将无法从您的 aspx 页面(Web 服务器)访问本地资源。您是否尝试过从 aspx 页面到 css 文件的相对路径,如下所示...

<link rel="stylesheet" media="all" href="/CSS/Style.css" type="text/css" />

The above assumes that you have a folder called CSSin the root of your website like this:

以上假设您CSS在网站的根目录中有一个文件夹,如下所示:

http://www.website.com/CSS/Style.css

回答by John Meyer

It is today possible to configure Safari to access local files.

现在可以配置 Safari 来访问本地文件。

  • By default Safari doesn't allow access to local files.
  • To enable this option: First you need to enable the develop menu.
  • Click on the Develop menu Select Disable Local File Restrictions.
  • 默认情况下,Safari 不允许访问本地文件。
  • 要启用此选项:首先您需要启用开发菜单。
  • 单击开发菜单选择禁用本地文件限制。

Source: http://ccm.net/faq/36342-safari-how-to-enable-local-file-access

来源:http: //ccm.net/faq/36342-safari-how-to-enable-local-file-access

回答by Michael

The solution is already answered here above (long ago).

上面已经回答了解决方案(很久以前)。

But the implicit question "why does it work in FF and IE but not in Chrome and Safari" is found in the error text "Not allowed to load local resource": Chrome and Safari seem to use a more strict implementation of sandboxing (for security reasons) than the other two (at this time 2011).

但是在错误文本“不允许加载本地资源”中发现了隐含的问题“为什么它在 FF 和 IE 中有效,而在 Chrome 和 Safari 中无效”:Chrome 和 Safari 似乎使用了更严格的沙箱实现(为了安全)原因)比其他两个(此时 2011 年)。

This applies for local access. In a (normal) server environment (apache ...) the file would simply not have been found.

这适用于本地访问。在(正常)服务器环境(apache ...)中,根本找不到该文件。

回答by JavaAllDay

I know this post is old but here is what I found. It doesn't work when I link it this way(with /before css/style.csson the hrefattribute.

我知道这篇文章很旧,但这是我发现的。当我以这种方式链接它时它不起作用(在属性上使用/before 。css/style.csshref

<link rel="stylesheet" media="all" href="/CSS/Style.css" type="text/css" />

However, when I removed /I'm able to link properly with the css file It should be like this(without /).

但是,当我删除时,我/能够与 css 文件正确链接它应该是这样的(没有/)。

<link rel="stylesheet" media="all" href="CSS/Style.css" type="text/css" />

This was giving me trouble on my project. Hope it will help somebody else.

这给我的项目带来了麻烦。希望它会帮助别人。