Not allowed to load local resource: file

For anyone landing here and working in asp.net:

I was having the same issue (not allowed to load local resource) in every browser except IE.

My workaround was to have the anchor direct to a handler & include a query string for the path:

<a href="https://stackoverflow.com/questions/25750742/handler.ashx?file=//server_name//dir//filename.pdf" />

Then the handler would write the file as the response (opens up in a new tab as desired with _self):

public void ProcessRequest (HttpContext context) {

        if (context.Request["file"] != null && !String.IsNullOrEmpty(context.Request["file"].ToString()))
        {
            try
            {
                context.Response.Clear();
                context.Response.ClearContent();
                context.Response.ClearHeaders();
                //whichever content type you're working with
                context.Response.ContentType = "application/pdf";

                //encode the path when you set the href of the anchor, so decode it now
                string file_name = HttpUtility.UrlDecode(context.Request["file"].ToString());
                context.Response.TransmitFile(file_name);

            }
            catch { }
        }
}

Leave a Comment