问题
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:
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:
This Stackoverflow Q/A states that the meaning of the forbidden icon is that the client is terminating/aborting the response
回答1:
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");
来源:https://stackoverflow.com/questions/12300154/unable-to-render-excel-download-from-aspx-page