Click here to Skip to main content
14,693,572 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

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. Its urgent..

string fileName=this.Controller.Model.SessionDataContext.FileAttachmentRowData.PhysicalFileName;
            byte[] array = this.Controller.Model.SessionDataContext.FileAttachmentRowData.FileContents;
            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);
Updated 27-Feb-20 20:46pm

1 solution


You may have used Response.Redirect twice continuously which causes this error.
Refer to :[^]
Ajay ghosalkar 17-Apr-12 10:07am
if removed response.flush then page will be redirected but i am not able to download has to be redirected after downloading file. so what to do that..pls give me right solution
jjackie1 18-Sep-13 7:07am
Have you got the answer for this probelm?? if so can you explain it here.

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