In my code, I want to redirect to a thankyou.html page after download pdf so that I crate download() in that method i write code
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);
}
}
But It shows me Error Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack and when Response.Redirect("thankyou.html"); take outside it show me error Cannot redirect after HTTP headers have been sent. Can you guide me how to redirect to another page?