When I call Response.Redirect(someUrl)
I get an HttpException: "Cannot redirect after HTTP headers have been sent".
Why do I get this? And how can I fix this issue?
When I call Response.Redirect(someUrl)
I get an HttpException: "Cannot redirect after HTTP headers have been sent".
Why do I get this? And how can I fix this issue?
There is one simple answer for this: You have been output something else, like text, or anything related to output from your page before you send your header. This affect why you get that error.
Just check your code for posible output or you can put the header on top of your method so it will be send first.
I solved the problem using: Response.RedirectToRoute("CultureEnabled", RouteData.Values); instead of Response.Redirect.
If you get Cannot redirect after HTTP headers have been sent then try this below code.
Just check if you have set the buffering option to false (by default its true). For response.redirect to work,
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. Of course, that depends on what HTML has already been sent down.
My Issue got resolved by adding the Exception Handler to handle "Cannot redirect after HTTP headers have been sent". this Error as shown below code