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.
If you are trying to redirect after the headers have been sent (if, for instance, you are doing an error redirect from a partially-generated page), you can send some client Javascript (location. replace or location. href, etc.) to redirect to whatever URL you want.
In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that start with 3 , and a Location header holding the URL to redirect to. When browsers receive a redirect, they immediately load the new URL provided in the Location header.
It's impossible to redirect to a page with custom headers set, no matter what language or framework you use. In other words, there's no way to trigger an HTTP redirect and cause the client (browser) to add a custom header.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With