Response.AddHeader无法在Chrome和Safari浏览器中使用 [英] Response.AddHeader is not working in Chrome and Safari Browsers
本文介绍了Response.AddHeader无法在Chrome和Safari浏览器中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码下载文件,下载文件后打开我的网站页面,但它只能在 Firefox
中使用浏览器。
它在其他浏览器中不起作用。
Hi,
I am using following code for downloading file and after downloading file its opens my site page, but its working only in Firefox
browser.
Its not working in other browsers.
Response.AddHeader("Refresh", "3; url=http://www.mysite.com/");
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=myfile.pdf");
Response.TransmitFile(Server.MapPath("myfile.pdf"));
Response.End();
推荐答案
我认为你的问题是浏览器不支持应用程序的刷新响应头/ octet-stream响应。
如果您需要在下载后将页面加载到隐藏的iframe中,我找到了最佳解决方案。
I think your problem is that the browsers dont support the refresh response header for application/octet-stream responses.
I found the best solution if you need a page load after a download is to put the download into a hidden iframe.
按照我之前对相同类型问题的回答。
如何在Response.TransmitFile 之后调用Response.Redirect [ ^ ]
As第二种方法是依赖于浏览器的,所以最好选择第一种方法,这种方法最近在许多现代网站中实现。
Follow my previous answer on same type of question.
how to call Response.Redirect after Response.TransmitFile[^]
As the second method is browser dependent, so better go for the first approach, which is implemented in many modern websites these days.
这篇关于Response.AddHeader无法在Chrome和Safari浏览器中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文