簡體   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