Skip to content

Cannot redirect after HTTP headers have been sent

Prabu Spark

Asked Dec 12, 2014, 12:03 AM EST1 answer
Share
LinkedInX
Hi sir,
I am getting the error "Cannot redirect after HTTP headers have been sent"
while redirecting to another page after the download operation.

I shared the code for your reference. Kindly give me the solution for this problem.



Default.aspx.cs:
*********************

Response.Clear();

Response.ContentType = "application/pdf";
string filePath = "d:\\" + filename + ".pdf";
Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", filePath));

Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.Buffer = true;

Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.Close();


Response.Redirect("StudentHome.aspx");

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi N Vinodh
     The link u gave , is index change event. I am asking about Redirection issue after downloading the file.
    0