ASP.NET 中 IE 7,8 中的“另存为”对话框出现问题
我正在尝试编写代码来下载位于服务器上的文件。 但另存为对话框不会在 IE 中打开。
我尝试了response.redirect,我尝试了
Response.Clear();
Response.ContentType = "text/csv";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileNameDisplay);
Response.WriteFile(Server.MapPath(pathName + fileNameUnique));
Response.Flush();
Response.End();
在 Firefox 和 chrome 上一切正常,但在 Internet Explorer 上不行。 我知道安全中有一个安全选项--->自定义级别--->下载--->自动提示文件下载,始终处于禁用模式,我需要将其切换为启用才能正常工作,但我不希望我的用户处理此问题。 我该如何克服这个“安全问题”?
有没有正确的方法来处理下载文件? 执行此操作的正确代码是什么?
谢谢你, 加迪姆
i'm trying to write code that download a file that located on the server.
but the save as dialog wont open in IE.
i tried response.redirect, i tried
Response.Clear();
Response.ContentType = "text/csv";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileNameDisplay);
Response.WriteFile(Server.MapPath(pathName + fileNameUnique));
Response.Flush();
Response.End();
every thing works on firefox and chrome , but not in internet explorer.
i know that there is a security option for this in security ---> custom level ---> Downloads ---> automatic prompting for file downloads , that is always in disable mode and i need to switch it to enable in order it to work, but i don't wont that my users deal with this.
how do i overcome this 'security problem' ?
is there any right way to deal with download files ?
what is the right code to do that ?
thank you,
gadym
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你需要明确告诉它不是打开的内容,
添加以下标头:
还强烈建议设置显式文件长度
You need explicitly tell that it is not opened content,
add following headers:
Also it is strongly recommend to set explicit file length
阿巴蒂什切夫,谢谢你帮助我。
我找到了解决问题的办法。
我创建了一个对话框窗口(我们称之为“DownloadWindow”),其中包含一个空的“A HREF”标签。
(它显示 - '单击此处下载')
在我单击默认页面上的下载(EXCEL/CSV 图标)按钮(这将创建我的文件
动态),
我加载对话框窗口(“DownloadWindow”),然后将“a href”链接替换为我之前创建的文件 URL,以便我的用户可以从我的服务器下载它。
现在,Internet Explorer确实弹出了打开/保存/取消对话框。
这有点烦人,但它解决了我的问题。
abatishchev, thank you for helping me.
i found a soultion to my problem.
I created a dialog window (let's call it 'DownloadWindow') which holds an empty 'A HREF' tag.
(it's shows - 'click here To Download')
after i click a download (EXCEL/CSV icon) button on my default page (which creates my file
dynamicly),
i load the dialog window ('DownloadWindow') and then i'm repleacing the 'a href' link to the file url i created earlier so my users can download it from my server.
Now, Internet explorer did pop up the open/save/cancel dialog box.
it's a bit annoying but it's solved my porblem.
当我使用以下方式创建文件下载链接时,我遇到了同样的问题:
当我将其更改为:时问题就消失了:
I had the same problem when my link for file download was made using:
The problem was gone when i changed it to: