asp.net - 使用 IE 通过 https(SSL) 导出到 excel 在 asp.net 网站中不起作用

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

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

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

这是一段代码

Response.Cache.SetAllowResponseInBrowserHistory(true);

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

    Response.CacheControl = "Public";

任何帮助都会很棒谢谢

最佳答案

     #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 工作表,您也可以使用它从物理位置获取文件。 :)

关于asp.net - 使用 IE 通过 https(SSL) 导出到 excel 在 asp.net 网站中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5213701/

相关文章:

css - 本地文件上的 Internet Explorer "CSS was ignored due to mime type mismatch"(无服务器)

java - ColdFusion 启用 RMI over SSL 以解决数据管理问题

url - https 站点上的 Xhtml 命名空间?

c# - 缓存大型数据集

asp.net - DataTypeAttribute 是 DefaultModelBinder 类的验证属性吗

CSS 菜单在 IE7 中左对齐 - 如何在所有浏览器(IE7、IE8、firefox 等)中使菜单居中

html - 使用响应式设计的图像不显示在 IE 中

javascript - 无需身份验证的node.js SSL加密

c# - 无法从代码隐藏中找到控件,但能够找到其他控件

jquery - 更改asp :label with jQuery then access in codebehind