Chrome & Safari Error::Not allowed to load local r

2019-01-17 03:25发布

问题:

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

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

Everything works fine in IE and FF.

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

<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?

回答1:

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...

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

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

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


回答2:

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).

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



回答3:

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

  • 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.

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



回答4:

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 href attribute.

<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 /).

<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.