Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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");
Posted

Hi,
What line i have to remove from the above two lines.
 
Share this answer
 
You cannot send send two response for one request. And here you have two. Remove the lines
C#
Response.Flush();
Response.Close();


and try
 
Share this answer
 
Comments
Prabu Spark 12-Dec-14 6:01am    
Hi,
What line i have to remove from the above two lines.
Brij 12-Dec-14 6:05am    
Remove both and and have you code like
Response.OutputStream.Flush();
Response.OutputStream.Close();

Response.Redirect("StudentHome.aspx");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900