I am getting exception "Cannot redirect after HTTP headers have been sent" when redirecting to another page
I am getting exception
"Cannot redirect after HTTP headers have been sent."
when on doing Response.Redirect("Home.aspx")
.开发者_如何学运维
How can i solve this?
I tried giving Response.Flush()
before redirecting.
The problem is the Response.Flush()
prior to redirecting. With HTTP you get one response for one request. Your browser requested the page only once, and I suspect you're trying to respond twice:
Response.Flush(); //First Response
Response.Redirect("Home.aspx"); //Second Response
Therefore taking this out the Response.Flush()
will solve your problem.
In my case, cause of the problem is that loading data in the scroll gridview is taking a long time. And before gridview data is not loaded exactly, but I press the redirect button.
Trying solve problem may be:
+lessen your data get
or
+before loading completion prevent to press redirect button
I just ran across this problem in a little different way. I had two Response.Redirect calls that were not wrapped in isolated branches of code. Worked fine in Chrome, but IE did not like it. It was an easy fix since I had two "if" statements. I just turned the second one into an "else if" like so...
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");
}
精彩评论