【发布时间】:2021-07-13 02:49:58
【问题描述】:
我有一个 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();
}
}
}
问题是,文件保存对话框正常出现,我也可以下载文件,但它没有被重定向到Thanks.aspx页面。
如何解决?
【问题讨论】:
标签: c# asp.net redirect download