Employers - Post Free Jobs
Forum guidelines
AuthorQuestion
Cannot redirect after http headers have been sent
Posted on: 18 Apr 2012
Hello
I am getting this error Message "cannot redirect after http headers have been sent"
when I am calling response.redirect ("home.aspx").
this error occured after downloading file from gridview which is infragistic control.following code to downloading file..
so how can i redirect to the page.
<pre lang="c#">string fileName=this.Controller.Model.SessionDataContext.FileAttachmentRowData.PhysicalFileName;
  byte[] array = this.Controller.Model.SessionDataContext.FileAttachmentRowData.FileContents;
  Response.Clear();
  Response.Buffer = true;
  Response.AddHeader("Content-disposition", "attachment; filename=" + fileName);
  Response.AddHeader("Content-Length", array.Length.ToString());
  Response.ContentType = "application/pdf";
  Response.OutputStream.Write(array, 0, array.Length);
  Response.Flush();
  Response.Clear();

ajay
AuthorReply
Re: Cannot redirect after http headers have been sent
Posted on: 18 Apr 2012  
Hi,

Remove the Response.Flush() and try to execute it.

Let me know.



If this post is useful then mark it as "Accepted Answer"
Re: Cannot redirect after http headers have been sent
Posted on: 22 Jun 2012  
Hi, I am also getting the same error. I have tried your solution.After removing Response.Flush(), document download pop up is not displaying but I can redirect the page.
Any solution how can i download the document and after downloading the document how can I redirect the page.

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.