IE7文件下载对话框消失
以下代码将无法在安装了最新服务包的 IE7 中正确运行。
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Disposition", "attachment;filename=Contacts.xls");
response.ContentType = "application/octet-stream";
System.Text.UnicodeEncoding Encoding = new System.Text.UnicodeEncoding();
byte[] unicodeBytes = {255,254};
int length = 2 + Encoding.GetByteCount(_exportContent); // _exportContent is string.
response.AddHeader("Content-Length", length.ToString());
response.OutputStream.Write(unicodeBytes, 0, 2);
unicodeBytes = Encoding.GetBytes(_exportContent);
response.OutputStream.Write(unicodeBytes, 2, unicodeBytes.Length);
response.End();
我用js(window.open())打开aspx页面并在Page_Load()中执行上述代码。
奇怪的是,窗口弹出,尝试加载/显示文件对话框,然后您听到好像弹出窗口已被阻止的声音(尽管弹出窗口阻止程序已停用!)。
额外信息:
- 这种行为在 XP 和 W2k3 上都会发生(这是一个真正的 Web 服务器,除了 IE7 和 FW 3.5 SP1 和最新的服务包之外,没有安装任何其他东西。) - 相同的代码在固件 2.0 上运行良好 - Firefox 显示文件对话框没有问题。
我很好奇是否有其他人遇到过同样的问题,并且可以提供一个解决方案来让这个东西在 IE7 中工作。
干杯,
迪米
The following code will not run correctly in IE7 with the latest service packs installed.
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Disposition", "attachment;filename=Contacts.xls");
response.ContentType = "application/octet-stream";
System.Text.UnicodeEncoding Encoding = new System.Text.UnicodeEncoding();
byte[] unicodeBytes = {255,254};
int length = 2 + Encoding.GetByteCount(_exportContent); // _exportContent is string.
response.AddHeader("Content-Length", length.ToString());
response.OutputStream.Write(unicodeBytes, 0, 2);
unicodeBytes = Encoding.GetBytes(_exportContent);
response.OutputStream.Write(unicodeBytes, 2, unicodeBytes.Length);
response.End();
I am opening the aspx page with js (window.open()) and execute the above code in the Page_Load().
The strange thing is that the window pops up, tries to load/show the file dialog and then you hear the sound like a popup window has been blocked (although popup blocker is deactivated!).
Extra information:
- The behavior happens both on XP and W2k3 (which is a real web server without anything else installed but IE7 & FW 3.5 SP1 & latest service packs.)
- The same code works fine with FW 2.0
- Firefox has no problems to display a file dialog.
I would be curious if anyone else has ran into the same problem and could provide a solution for getting the thing working in IE7.
Cheers,
Dimi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要测试安全是否导致此问题,请将目标设置为 _self。 IE 顶部的警告栏应该出现。
如果这是原因,请检查 IE 安全性。 具体是下载部分的提示。
To test if security is causing this issue, set the target to _self. The warning bar on top of IE should appear.
If this is the cause, check IE security. Specifically the prompt for download part.
我仍然无法让对话框不消失。 当应用程序访问 [webmethod] 来收集信息以传递到尝试将结果下载到 Excel 的页面时,就会发生这种情况。
这似乎也仅在使用 IP 地址(999.11.1.111\default.aspx...)访问网站时才会发生。 通过 loacalhost\default.aspx 访问它时它可以工作
I still can not get the dialog box to not disappear. This happens when the application accesses a [webmethod] to gather information to pass to the page that is trying download the results to excel.
This also only appears to happen when accessing the web sit using an ip address (999.11.1.111\default.aspx....). It works when accessing it via loacalhost\default.aspx
我们的内联网上出现了这个问题,自动提示下载对我来说不起作用(已选择),但这确实...
工具 -> Internet 选项
在“安全”选项卡上选择“本地 Intranet”,然后单击“站点”
单击“高级”
输入“http://your.url.com”,然后单击“添加”
单击“关闭”-> 好的-> 好的,
希望这也适合你;)
Had this problem on our intranet, automatic prompting for downloads didn't work for me (was already selected) but this did...
Tools -> Internet Options
On Security tab select ‘Local intranet’ then click Sites
Click Advanced
Type “http://your.url.com” and click Add
Click Close -> Ok -> Ok
hope this works for you too ;)
添加一个标头,明确告诉 IE 缓存该文件。 IE 存在已知错误,如果文件作为无缓存文件发送,则无法正确保存该文件。
Add a Header telling IE explicitly to CACHE the file. IE has known bugs with not being able to properly save a file if it is sent as a no-cache file.
我也遇到了同样的问题,花了一个小时感到非常沮丧。 与往常一样,微软 IE 浏览器是所有令人头痛的根源。 在其他浏览器中一切正常。 解决方案很简单:
用户必须通过以下方式调整 IE7 设置:
'工具'> '互联网选项'> “安全”选项卡> 对于“Internet”和/或“本地 Intranet”,通过单击“自定义级别...”按钮调整安全设置,
转到“下载”节点“>” 文件下载自动提示'> 检查“启用”
这为我的用户解决了这个问题。
希望有帮助。
I had the same issue, and spent an hour being utterly frustrated. As usual microsoft IE browsers are the root of all headaches. Everything worked fine in other browsers. The solution is simple:
The user will have to adjust an IE7 setting by going to
'Tools' > 'Internet Options' > 'Security' Tab > For 'Internet' and/or 'Local intranet' adjust the security settings by clicking the button, 'Custom level ...'
Go to the 'Downloads' node '> Automatic prompting for file downloads' > check 'Enable'
That fixed it for my users.
Hope that helps.