在ASP.NET中下载文件后重定向页面 [英] Redirect page after file is downloaded in ASP.NET

查看:70
本文介绍了在ASP.NET中下载文件后重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp按钮,点击按钮我的文件正在下载但我需要在文件下载后回发页面或重定向页面。



i已经使用

i have a asp button, on clicking button my file is downloading but i need to postback the page or redirect a page after file is downloaded.

i have already used

1.Response.AddHeader("Refresh", "3;URL=frmDashboard.aspx");
2.Removed response.end(),response.flush(),response.close();

但仍未收到回发





请帮帮我



我的尝试:



but still not getting postback


please help me

What I have tried:

string filePath = "E:\\FileName.docx;         
           Response.ContentType = ContentType;
           Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
           Response.WriteFile(filePath);
           Response.Flush();
           HttpContext.Current.ApplicationInstance.CompleteRequest();
           Response.Close();

推荐答案

请参阅我的提示/文章,只需修改代码如下



ASP.NET导出Excel - 下载后的Javascript事件 [ ^ ]



Refer my Tip/Article and just modify the code as below

ASP.NET Export Excel - Javascript event after download[^]

var loop = setInterval(function () {
         if (IsCookieValid()) {
             document.getElementById('imgloadinggif').style.display =  'none'; clearInterval(loop)
             // your code here..
             window.location.reload(); // reload the page
         }

     }, timeInterval);


当用户请求下载文件的页面时,您只能发送一个响应,而该响应是客户端的文件流下载。下载本身由用户的浏览器处理,您不知道该文件是否已下载。如果你想做一个也是一个响应的重定向,如上所述,你只能发送一个响应...下载或重定向,你不能同时做两个。



所以基本上你不能这样做。
When the user requests the page that downloads the file you can only send one response, and that response is the file stream for the client to download. The download itself is handled by the user's browser and you don't know if the file has been downloaded or not. Add to that if you want to do a redirect that is also a response and as above you can only send one response...a download or a redirect, you can't do both.

So basically you just can't do this.


这篇关于在ASP.NET中下载文件后重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆