无法从aspx页面呈现excel下载

时间:2012-09-06 12:28:41

标签: c# asp.net internet-explorer iis http-headers

我有一个ASP.NET(webforms)页面,只需点击一下按钮就可以将MS-Excel呈现给响应流。一切都在测试中完美运行,但在实时部署中,我在浏览器出现尝试下载文件后得到此对话框: enter image description here 其中ReportsShow.aspx是生成和呈现excel的aspx页面的名称。 触发下载的按钮会触发回发,因此我很困惑为什么在加载时正确呈现页面时无法找到该页面? 我很无能,任何帮助将不胜感激

编辑:根据Mayank的要求,这是代码结构:

        // 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);
            }
        }

更多信息

我用fiddler对此进行了分析,这就是我所看到的特定请求/响应,预计会提供下载的excel:

enter image description here

This Stackoverflow Q/A表示禁止图标的含义是客户端正在终止/中止响应

0 个答案:

没有答案