I get an exception "Cannot redirect after sending HTTP headers" when redirecting to another page

I get an exception

"Cannot redirect after HTTP headers have been sent." 

when executing Response.Redirect("Home.aspx") .

How can i solve this? I tried to provide Response.Flush() before the redirect.

+7
source share
3 answers

The problem is Response.Flush() before the redirect. Using HTTP, you get one response for one request. Your browser only requested the page once, and I suspect you are trying to respond twice:

 Response.Flush(); //First Response Response.Redirect("Home.aspx"); //Second Response 

Therefore, given this, Response.Flush() will solve your problem.

+8
source

In my case, the cause of the problem is that loading data into the scroll view grid takes a lot of time. And before the grid data is not loaded exactly, but I press the redirect button.

An attempt to solve the problem could be:

+ reduce your data

or

+ before completing the download do not click the redirect button

0
source

I just ran into this problem a little differently. I had two calls to Response.Redirect that were not wrapped in isolated code branches. It worked fine in Chrome, but IE didn't like it. This was a simple solution, as I had two if statements. I just turned the second into an "else if" like this ...

 if (QueryString("reset") == "1") { // User is resetting password Response.Redirect("/Account/ResetPassword.aspx"); } else if (DataUtils.IsInt(QueryString("id"))) { // User is authenticating...completing signup Response.Redirect("/Account/Activate.aspx"); } 
-2
source

All Articles