I have a master page with a logout link on it. When the user clicks the link I call the following method:
private void Logout()
{
SessionBll.DeleteSessionEntry(this.sessionId);
FormsAuthentication.SignOut();
Roles.DeleteCookie();
LogHelper.Location = string.Empty;
LogHelper.Info(logger, HttpContext.Current.User.Identity.Name,
MethodBase.GetCurrentMethod().Name, "User has been logged out from
Administrator.Master", LogMessage.LoggedOut);
FormsAuthentication.RedirectToLoginPage();
}
Now, when a user is on a page and they click the link, the normal page cycle happens and this method is called.
The problem with this is that the user shouldn’t have to wait for the page cycle, they should be taken to the logout page as fast as possible (as long as it takes to run the logout method on the server).
How do I skip the page life cycle, yet still call this method?
Thanks.
You can’t skip the page life cycle; what you can do instead is this:
Change that
logoutlink to a normal link (<a href="...">) and onPage_Loadof theLoginpage, execute that code you posted but onlyif(!IsPostBack)Edit
If your Login page needs to know (as you put it) when to execute your cleanup code; you can pass a parameter on the logout link as so:
And then check on Page_Load:
This is super fast.