PDF下载后重定向页面

pri*_*ore 4 c# asp.net redirect download

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

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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

怎么解决这个?

WVD*_*ick 6

我发现将PDF下载页面放在iframe中更容易.这样,只需将iframe源指向PDF下载页面,即可在客户端激活PDF下载.之后,您可以移动到新页面,也可以只在页面中显示iframe,并在其中显示iframe.


win*_*ute 5

如果只是下载文件,则不进行任何预处理,您可以尝试以下操作:

Response.AddHeader("Refresh", "12;URL=nextpage.aspx");
Run Code Online (Sandbox Code Playgroud)

数字是刷新完成前的秒数:)