我正在尝试从 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/