Cannot redirect after HTTP headers have been sent

Posted by Prabu_Spark under ASP.NET on 12/12/2014 | Points: 10 | Views : 3566 | Status : [Member] | Replies : 1
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");

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: kgovindarao523-21772 on: 12/15/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
Its just an assumption. Try to add
Response.Clear();
even before the
Response.Redirect("StudentHome.aspx");

Thank you,
Govind

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response