繁体   English   中英

无法呈现从ASPX页面下载的Excel

[英]Unable to render excel download from aspx page

我有一个ASP.NET(网络表单)页面,单击按钮即可将MS-Excel呈现回响应流。 一切都可以在测试中正常运行,但是在实时部署中,浏览器似乎正在尝试下载文件后,出现了这个对话框: 在此处输入图片说明 其中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);
            }
        }

更多信息

我已经用提琴手对此进行了分析,这是我对特定请求/响应所看到的,该请求/响应有望提供可下载的excel:

在此处输入图片说明

此Stackoverflow Q / A指出,禁止图标的含义是客户端正在终止/中止响应

我已经找到解决此问题的方法。 详细信息如该链接中所述

这样的问题有一些细节和资源可以澄清正在发生的事情。 基本问题是,当IE 8和更低版本在响应中看到以下标头时,无法通过SSL下载文件:高速缓存控制:no-cache语法:no-cache

这些标头应删除并替换为:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM