在我的代码中,我想在下载pdf之后重定向到thankyou.html页面,以便我在该方法中创建download()我编写代码
protected void download()
{
try
{
string path = Server.MapPath("pdf/myDoc.pdf");
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
string strURL = path;
WebClient req = new WebClient();
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.AddHeader("Content-Disposition", "attachment;filename=\"myDoc.pdf\"");
byte[] data = req.DownloadData(path);
Response.BinaryWrite(data);
Response.Flush();
Response.Redirect("thankyou.html");
}
else
{
Response.Write("This file does not exist.");
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('" + ex.Message.ToString() + "');", true);
}
}
Run Code Online (Sandbox Code Playgroud)
但它显示我无法评估表达式,因为代码已优化或本机框位于调用堆栈之上且当Response.Redirect("thankyou.html"); 在外面它显示我错误在HTTP标头发送后无法重定向. 你能指导我如何重定向到另一个页面吗?