Wednesday, June 27, 2007

Ending an ASP.NET Response during processing.

Your ASP.NET 2.0 page is in the middle of processing a Request (thus creating a Response), when all of the sudden you need to stop the request. Why? Well, say you just called:


FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();


And now you need the current Response to stop processing (no more event handlers to fire, etc). How do you do that? That's the question I had for some time, but didn't have time to investigate it further. After familiarizing myself more with the objects in HttpContext.Current, It became more obvious with where I needed to look, and there it was:


HttpContext.Current.Response.End();


The description says that this method "Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event." Nice.

No comments:

Disqus for A Nofsinger's Blog