Skip to content Skip to sidebar Skip to footer

Cannot Open Anchor Links Pointing To File In Chrome

In our ASP MVC 3 site, we have some hyperlinks that point towards files out on our LAN (this is an intranet site). These links have ALWAYS worked up until today.. at which point no

Solution 1:

Did you try using forward slashes instead. I mean instead of

<ahref="\\Prdhilfs03\l&amp;i-sales&amp;mkt\WORKAREA\Agencyservices\Shared\AIC\MasterListAttachments\AF.xls"class="noLine"></a>

to use

<ahref="//Prdhilfs03/l&amp;i-sales&amp;mkt/WORKAREA/Agencyservices/Shared/AIC/MasterListAttachments/AF.xls"class="noLine"></a>

Convert the urls:

var links = document.querySelectorAll("a");
for(var i=0; i<links.length; i++) {
    var link = links[i];
    var url = link.getAttribute("href");
    if(url) {
        url = url.replace(/\\/g, "/");
        link.setAttribute("href", url);
    }
}

Solution 2:

First of all, prefix your href with "file://" instead of "\\", and this will fix the discrepancy between the two links.

Second, I believe that your problem has to do with cross site scripting. Your browser doesn't want to be tricked into downloading files from another server (I'm assuming that \\Prdhilfs03 is a different computer than the web server).

To verify this problem using Chrome, click on the link while your javascript console is open, and see if you get an error that says something like "Not allowed to load local resource:".

EDIT

OK, as verified by your error message, your web browser is preventing you from downloading a file from a different server to protect against cross site scripting. There is an article here that talks about steps to fix this by changing your chrome settings, although another option would be to store the files locally on the web server.

Solution 3:

I'll add to Karl's answer that you are running into the cross site scripting issue. An alternative you have is to have a controller that returns the file in question as a FileResult. Let's call this a FileRouter. The FileRouter will then have one action called Download, something like this:

public FileContentResult Download(string path)
{
    returnthis.File(/* a stream to the path */);
}

You would then pass the paths to the action on your controller. So instead of a direct link, you'll place an Html.Action link with a target of intranetserver/filerouter/download?path=path_to_file

Of course this has the drawback of the server loading the file off the network unnecessarily, but it's an alternative to consider.

Additionally, using a FilePathResult may work here as well, but I don't have any experience with it so can't make any claims on its efficacy here.

Post a Comment for "Cannot Open Anchor Links Pointing To File In Chrome"