【问题标题】:exporting to excel over https(SSL) using IE is not working in asp.net website使用 IE 通过 https(SSL) 导出到 excel 在 asp.net 网站中不起作用
【发布时间】:2011-07-09 23:31:23
【问题描述】:

我正在尝试从 https 站点导出 excel 文件,它非常适合 firefox 和其他浏览器,但在 IE 中,它给我的错误是该站点不可用或找不到文件。

我研究了这个问题,发现它与缓存相关,所以我更改了此页面中的标题,以便允许缓存,但它仍然无法正常工作。

这是代码的快照

Response.Cache.SetAllowResponseInBrowserHistory(true);

    Response.Cache.SetCacheability(HttpCacheability.Public);
    Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));
    Response.Cache.SetAllowResponseInBrowserHistory(true);

    Response.CacheControl = "Public";

任何帮助都会非常感谢您

【问题讨论】:

    标签: asp.net internet-explorer ssl https export-to-excel


    【解决方案1】:
         #region For Download to work on HTTPS
    
        Response.ClearHeaders();
        Response.Cache.SetCacheability(HttpCacheability.Private);
        Response.Buffer = true;
        Response.AddHeader("Content-Transfer-Encoding", "binary");
    
         #endregion
    
        Response.Clear();      
        Response.AddHeader("content-disposition", "attachment;filename=Temp.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.xls";
        StringWriter strWriter = new StringWriter();
        HtmlTextWriter htmlWrite = new HtmlTextWriter(strWriter);
        string heading = "<h4 align='left'>Temp Excel Cube</h4>";
        strWriter.Write(heading);
        gvTemp.RenderControl(htmlWrite);
        Response.Write(strWriter.ToString());
        Response.End();
    

    我想这就是你要找的。它适用于 HTTPS,我已将网格导出到 Excel 工作表,您也可以使用它从物理位置获取文件。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-13
      相关资源
      最近更新 更多