When I call Response.Redirect(someUrl) I get the following HttpException:
Cannot redirect after HTTP headers have been sent.
Why do I get this? And how can I fix this issue?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
According to the MSDN documentation for
Response.Redirect(string url), it will throw an HttpException when ‘a redirection is attempted after the HTTP headers have been sent’. SinceResponse.Redirect(string url)uses the Http ‘Location’ response header (http://en.wikipedia.org/wiki/HTTP_headers#Responses), calling it will cause the headers to be sent to the client. This means that if you call it a second time, or if you call it after you’ve caused the headers to be sent in some other way, you’ll get the HttpException.One way to guard against calling Response.Redirect() multiple times is to check the
Response.IsRequestBeingRedirectedproperty (bool) before calling it.