Why do I get “Cannot redirect after HTTP headers have been sent” when I call Response.Redirect(url)?
richard wrote:When I call Response.Redirect(someUrl) I get an HttpException: "Cannot redirect after HTTP headers have been sent".
Just as the error states, you cannot do a redirect once headers, or any
parge of the page, has been sent to the client. An alternative to what you
are doing would be to just write client side script directly into the
response.
i.e.
Response.Write("<script
language=javascript>window.navigate('mynewpage.aspx);</script>")
Response.End
The above script is not a function so it will execute inline immediately
when sent to the browser and direct client to another page. Think of it as
an immediate client side redirect.