在 SSL (https) 下,导出到 Excel 不适用于 IE

发布于 2024-10-11 20:01:38 字数 1163 浏览 7 评论 0原文

我一直在尝试修复安全网站 (https) 上的某些内容,该网站是一个生成 CSV 文件的“导出到 Excel”按钮。

它适用于 Firefox、Chrome 等,但不适用于 Internet Explorer。

我已经更改了标头,消除了无缓存 还编辑了 IIS http 标头配置,将到期日期设置为 1 天。

我不知道发生了什么以及如何解决它。

你们知道如何解决这个问题吗?我读过很多帖子,他们都在说同样的事情……缓存。

谢谢,

更新 1:

关于我收到的错误,我收到一条 IE 警报,提示“Internet Explorer 无法从 web.address.com 下载 filename.aspx Internet Explorer 无法打开此 Internet 站点。请求的站点不可用或无法找到。请稍后重试。

正如我所说,这一切都通过 SSL (https) 进行,但导出到 Excel 按钮会中断 https。

更新 2:

我正在使用这些标头:

Response.ClearContent();
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=" + name.Trim() + ".csv");
                Response.AddHeader("Cache-Control", "no-cache");
                Response.AddHeader("Pragma", "public");
                Response.AddHeader("Content-Transfer-Encoding", "binary");
                Response.AddHeader("Content-Length", "2026");

                Response.Charset = "";
                //Response.ContentType = "application/vnd.ms-excel";
                Response.ContentType = "text/csv";

I've been trying to fix something on a secure website (https) which is an Export to Excel button that generates a CSV file.

It works on Firefox, Chrome , etc... but not in Internet Explorer.

I have changed the headers eliminating the no-cache
and also edited the IIS http header configuration setting an expiration date of 1 day.

I have no idea of what can be going on and how to solve it.

Do you guys have any idea of how to fix this stuff ? I've read so many posts and they're all saying the same thing... caching.

Thanks,

UPDATE 1 :

regarding the error I receive, I receive an IE Alert saying "Internet explorer cannot download filename.aspx from web.address.com
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

As I said, it all works out of SSL (https), but the export to excel button, breaks in https.

UPDATE 2:

I'm using these headers:

Response.ClearContent();
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=" + name.Trim() + ".csv");
                Response.AddHeader("Cache-Control", "no-cache");
                Response.AddHeader("Pragma", "public");
                Response.AddHeader("Content-Transfer-Encoding", "binary");
                Response.AddHeader("Content-Length", "2026");

                Response.Charset = "";
                //Response.ContentType = "application/vnd.ms-excel";
                Response.ContentType = "text/csv";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

飘逸的'云 2024-10-18 20:01:38

该问题是因为,在 IE9 之前,使用缓存控制标头 (http:// /support.microsoft.com/kb/323308)。

只需删除: Response.AddHeader("Cache-Control", "no-cache");

这适用于 IE 6,7 和 IE 6.7 的 https。 8.

The issue is because, before IE9, Internet Explorer downloads do not work over SSL when using cache control headers (http://support.microsoft.com/kb/323308).

Just remove: Response.AddHeader("Cache-Control", "no-cache");

This works in https for IE 6,7 & 8.

Microsoft 更改了 IE,使其不自动转换纯文本文件(例如 CSV)。您必须发送正确的 MIME 类型。不过,我手头没有这些信息。

Microsoft changed IE to not automatically convert a plain text file (e.g. CSV). You have to send the right MIME type. I don't have the info handy, though.

半边脸i 2024-10-18 20:01:38

过去在使用 IE 和 ssl 时遇到过问题,我发现以下标头

Cache-Control: cache, must-revalidate
Pragma: public
Content-Type: application/vnd.ms-excel  // MIME type
Content-Disposition: attachment; filename="excelDownload.xls"
Content-Transfer-Encoding: binary
Content-Length: 1024  // size as appropriate

对我有用(除了通常的 Expires 和 Last Modified 标头之外)

Having had problems with IE and ssl in the past, I've found that the following headers

Cache-Control: cache, must-revalidate
Pragma: public
Content-Type: application/vnd.ms-excel  // MIME type
Content-Disposition: attachment; filename="excelDownload.xls"
Content-Transfer-Encoding: binary
Content-Length: 1024  // size as appropriate

work for me (in addition to the usual Expires and Last Modified headers)

Saygoodbye 2024-10-18 20:01:38

我的解决方案与前一个人(TGuv)非常相似。我删除了以下行代码,它工作正常:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

My solution is very similar to the previous person (TGuv). I removed the following line of code it works fine:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
冰火雁神 2024-10-18 20:01:38

添加请求参数,它将起作用-

response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Cache-Control", "max-age=30");
response.setHeader("Pragma", "public");
response.setContentType("application/docx");

Add the request Parameters and it will work-

response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Cache-Control", "max-age=30");
response.setHeader("Pragma", "public");
response.setContentType("application/docx");
心的憧憬 2024-10-18 20:01:38

我们在工作中遇到了这个问题,结果证明这是 Internet Explorer(在我们的例子中为 IE8-)中的一个错误,在尝试使用 SSL 下载文件时会出现错误。问题是,如果服务器向浏览器发送禁用缓存的 http 标头,则 Explorer 会给出错误。

服务器端的解决方案是您应该覆盖此标头以告诉 IE8 缓存响应,例如使用 Cache-Control: private 。
请注意,某些应用程序服务器(例如我们的示例中的 Websphere Application Server)会在设置 cookie 时自动附加 no-cache="Set-Cookie"

最后,还有另一种解决方案(如果适用)可以解决该问题,但它应该应用于浏览器客户端:

查看方法 1:
http://support.microsoft.com/kb/2549423

We faced this problem at work, it turned out to be a bug in Internet Explorer (in our case IE8-), that gives an error when trying to download a file in SSL . The problem is that if the server sends to the browser an http header that disables caching, Explorer gives an error.

The solution server side is that you should overwrite this header to tell IE8 to cache the response, with Cache-Control: private for example.
Be careful that some application servers (such as in our case Websphere Application Server) append automatically no-cache="Set-Cookie" when a cookie is set.

Finally, there is another solution, if applicable, that solves the problem, but it should be applied client-side on the browser:

look at Method 1:
http://support.microsoft.com/kb/2549423

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文