问题描述
我有一个 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.
如何解决这个问题?
推荐答案
我发现将 PDF 下载页面放在 iframe 中更容易.这样,您只需将 iframe 源指向 PDF 下载页面即可在客户端激活 PDF 下载.之后,您可以移动到新页面,也可以直接在包含 iframe 的页面上显示感谢文本.
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 后重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!