下载后重定向到另一个页面 [英] Redirect to another page after download

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

问题描述


我的下载模块有问题.我的要求是,在下载文档或文件后,我需要重定向到另一页.可能吗?我已经尝试过

1. Response.Redirect("~/xyz.aspx");

2. Server.Transfer

3. Response.Write("<script type="text/javaScript"> window.location.href = ''~/xyz.aspx''; </script>");

我在这里输入我的代码:

Hi
I have a problem with Download module. My requirement is that, after downloading a document or a file, i need to redirect to another page. Is it possible? I already tried like

1. Response.Redirect("~/xyz.aspx");

2. Server.Transfer

3. Response.Write("<script type="text/javaScript"> window.location.href = ''~/xyz.aspx''; </script>");

Here i am putting my Code:

string URL = Server.MapPath("~/xyz.pdf");
        FileInfo fileInfo = new FileInfo(URL);

        if (fileInfo.Exists)
        {
            Response.Clear();
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
            Response.AppendHeader("Content-Length", fileInfo.Length.ToString());
            Response.ContentType = "application/pdf";
            Response.Flush();
            Response.WriteFile(fileInfo.FullName);

            Response.Write("<script type="text/javaScript"> window.location.href = 'Default.aspx'; </script>");
        }
        else
        {
                    Response.Write("<script>alert('Sorry u cant download file!')</script>");
        }


他们不工作.请帮助我紧急.
等待回应请让我知道我在哪里弄错了.
紧急.

谢谢u


They dont work. Please help me its urgent.
Waiting for the response & Please let me know where i made a mistake.
its urgent.

thank u

推荐答案

下面是一个很好的示例:

http://encosia.com/2007/02/23/ajax-file-downloads -and-iframes/ [ ^ ]
Here''s a nice example of how it could be done:

http://encosia.com/2007/02/23/ajax-file-downloads-and-iframes/[^]


一旦编写了标头内容,就无法将其更改为其他内容.我不确定您要做什么是否行得通.您需要解决它.

解决这些问题的一种方法是,在新窗口中打开下载链接,然后可以从父窗口重定向到其他窗口.
Once you write your header content you can''t change it to something else. I''m not sure if what you want to do will work. You need to work around it.

One way to work around them is, open your download link in new window and then you can redirect to different window from the parent window.


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

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