IE信息栏,下载文件......我该怎么编码呢?

时间:2022-01-12 01:50:55

I have a web page (asp.net) that compiles a package then redirects the user to the download file via javascript (window.location = ....). This is accompanied by a hard link on the page in case the redirect doesn't work - emulating the download process on many popular sites. When the IE information bar appears at the top due to restricted security settings, and a user clicks on it to download the file, it redirects the user to the page, not the download file, which refreshes the page and removes the hard link.

我有一个网页(asp.net)编译包,然后通过javascript(window.location = ....)将用户重定向到下载文件。如果重定向不起作用,则会在页面上附带硬链接 - 在许多热门网站上模拟下载过程。当IE信息栏由于受限制的安全设置而出现在顶部,并且用户单击它以下载文件时,它会将用户重定向到页面,而不是下载文件,刷新页面并删除硬链接。

What is the information bar doing here? Shouldn't it send the user to the location of the redirect? Am I setting something wrong in the headers of the download response, or doing something else wrong to send the file in the first place?

信息栏在这里做什么?它不应该将用户发送到重定向的位置吗?我是否在下载响应的标题中设置了错误,或者首先发送其他错误的文件?

C# Code:

m_context.Response.Buffer = false;
m_context.Response.ContentType = "application/zip";
m_context.Response.AddHeader("Content-Length", fs.Length.ToString());
m_context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}_{1}.zip", downloadPrefix, DateTime.Now.ToString("yyyy-MM-dd_HH-mm")));
//send the file

1 个解决方案

#1


When a user agrees to download a file using the IE Information Bar, IE reloads the current page, not the page the file the user is trying to download. The difference is that, once the page is reloaded, IE will allow the download script to go through without prompting the user. I'm not sure what the thinking is on this from a design standpoint, but that's how it seems work.

当用户同意使用IE信息栏下载文件时,IE会重新加载当前页面,而不是用户尝试下载的文件页面。不同之处在于,一旦重新加载页面,IE将允许下载脚本通过而不提示用户。从设计的角度来看,我不确定这个想法是什么,但这就是它的工作方式。

#1


When a user agrees to download a file using the IE Information Bar, IE reloads the current page, not the page the file the user is trying to download. The difference is that, once the page is reloaded, IE will allow the download script to go through without prompting the user. I'm not sure what the thinking is on this from a design standpoint, but that's how it seems work.

当用户同意使用IE信息栏下载文件时,IE会重新加载当前页面,而不是用户尝试下载的文件页面。不同之处在于,一旦重新加载页面,IE将允许下载脚本通过而不提示用户。从设计的角度来看,我不确定这个想法是什么,但这就是它的工作方式。