Pregunta

I am developing an application that allows the user to download an excel file with regular content(not bigger then a few Mb).

On IE9 the file gets downloaded perfectly, but on IE8 some of the pages that allow the download does not work.

A new page is opens and closed right away without showing the download bar.

The cache control header is set to private.

I have disabled all of my IE8 add ones.

I have matched the response from the server for both the page that does allow the file saving and the one that does not work and they match exactly ( apart from the path )

I dont know why on some cases the file gets download perfectly and on others it dont.

Here is the server side code that I use to download the file:

protected void GetExportedFile()
{
    string filename = Form("filename");

    if (string.IsNullOrEmpty(filename))
    {
        Logger.Instance.Write("GetExportedFile is missing the parameter filename");
        Response.Redirect("ErrorPage.aspx");
    }

    string filePath = Context.Server.MapPath("****/****/" + filename);

    Response.ClearHeaders();
    Response.ClearContent();
    SetContentType(ContentType.Excel);
    Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
    Response.WriteFile(filePath);

    Response.Flush();

    try
    {
        File.Delete(filePath);
    }
    catch (Exception ex)
    {
        Logger.Instance.Write(
            "GetExportedFile failed to delete the file '" + filePath + 
            "', Error: " + ex.ToString(), "Error");
    }

    try
    {
        Response.End();
    }
    catch (ThreadAbortException ex)
    {
        //Don't add anything here.
        //because if you write here in Response.Write,
        //that text also will be added to your text file.
    }
}

I have to mention although I dont think it is relevant that prior to the downloads that don't work on IE8 I am making some ajax calls to get notify if the excel generation has finished, while on the page that does work I dont do this procedure.

I will also like to add that my application resides behind an application firewall (F5) and when deactivated makes all of the downloads work on IE8, the issue is I am not not seeing any changes in the response.

thanks

¿Fue útil?

Solución

If anyone see this post, I have found the reason for the problem. IE8 has a security policy that will not allow a file download to be invoked directly from a script request.

Since I have invoked a series of ajax calls to the server querying the file creation state and when the file was ready issued a download call, IE has canceled it.

To override IE8 policy, when the file creation has finished I have poped the client a window with a link to the file , when that link was clicked the file got downloaded successfully.

I hope it helps someone one day...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top