Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an ASP.NET (webforms) page that renders MS-Excel back to the response stream on click of a button. Everything works perfectly in testing but on live deployment, I get this dialogue box after the browser appears to be trying to download the file: enter image description here where ReportsShow.aspx is the name of the aspx page that generates and renders the excel. The button that triggers the download fires a postback so I am confounded as to why the page would not be found when it renders correctly on load? I am clueless and any help would be greatly appreciated

EDIT: As requested by Mayank, here's the code structure:

        // Get instance of reporting service
        IReportingService reportingServiceClient = Reports.GetWebService();
        // Get a fresh copy of the report
        BusinessReport theReport = reportingServiceClient.GetReport(AcctList.ToArray());

        ExcelExport excelExport = new ExcelExport();

        const string templateFileName = "Business-Report.xls";
        string newFileName = String.Empty;

        try
        {
            newFileName = excelExport.CopyTemplateFile(Server.MapPath("~/ExportTemplates/" + templateFileName));
            excelExport.WriteData(forexOptionReport, newFileName);

            Response.Clear();

            Response.AddHeader("content-disposition", string.Format("Attachment; filename="{0}"", "Business-Report" + ".xls"));
            Response.ContentType = "application/vnd.ms-excel";

            Response.TransmitFile(newFileName);
            Response.Flush();
        }
        catch (Exception ex)
        {
            Errors.LogException("Error in Reports.BtnDownloadToExcel_Click", ex);
            throw;
        }
        finally
        {
            if (!String.IsNullOrEmpty(newFileName))
            {
                excelExport.DeleteFile(newFileName);
            }
        }

MORE INFO

I've analyzed this with fiddler and this is what I see for the particular request/response which is expected to present the excel for download:

enter image description here

This Stackoverflow Q/A states that the meaning of the forbidden icon is that the client is terminating/aborting the response

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
174 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have found the solution to this issue. The details are as described in this link

This SO question has some details and resources that would clarify what was happening. The basic issue is that IE versions 8 and below fail to download files over SSL when they see the following headers in the response: Cache-control: no-cache Pragma: no-cache

These headers should be removed and replaced with:

Response.Headers.Set("Cache-Control", "private, max-age=0");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...