在PDF下载之后重定向页面 [英] Redirecting a page after a PDF download

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

问题描述

我有一个aspx(说1.aspx)页面,首先我正在下载一个pdf文件,然后我想重定向到一些Thanks.aspx页面。代码是这样的:

I have an aspx (say 1.aspx) page from where first I am downloading a pdf file and then I want to redirect to some Thanks.aspx page. The code is this:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    string pathId = string.Empty;
    if (Page.IsValid)
    {
        try
        {    
            pathId = hidId.Value;
            DownloadPDF(pathId);                        

            Response.Redirect("Thanks.aspx");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}



protected void DownloadPDF(string pathId)
{
    if (!(string.IsNullOrEmpty(pathId)))
    {
         try
        {
            Response.ContentType = "application/pdf";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + pathId + ".pdf");
            string path = ConfigurationManager.AppSettings["Pdf_Path"].ToString() + "\\" + pathId.Trim() + ".pdf";
            Response.TransmitFile(path);                   
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    }
}

问题是,文件保存对话框正确到位,我也可以下载文件,但是没有被重定向到Thanks.aspx页面。

The problem is that, the file save dialog is coming properly and I am able to download the file also, but it is not getting redirected to the Thanks.aspx page.

如何解决这个问题? / p>

How to resolve this?

推荐答案

我发现将PDF下载页面放在iframe中更容易。这样,您可以通过将iframe源指向PDF下载页面来激活客户端的PDF下载。之后,你可以移动到一个新的页面,或者只是在页面上显示感谢文本。

I've found it easier to put the PDF download page in an iframe. That way you can activate the PDF download on the client side by just pointing the iframe source to the PDF download page. After that you can either move to a new page, or just show the thank you text right that on the page that has the iframe in it.

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

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