Reputation: 101
How can I implement logout feature on my page so that user is redirected to a login page and is not allowed to view previous page?
FormsAuthentication.SignOut(); is it enough for logout.
Upvotes: 2
Views: 1753
Reputation: 1690
/// <summary>
/// Logs the user out of their forms authentication.
/// </summary>
public void SignOut()
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}
Upvotes: 3
Reputation: 62260
You also want to remove the session state after SignOut.
FormsAuthentication.SignOut();
// Remove all session variables and destroy session
context.Session.RemoveAll();
context.Session.Clear();
context.Session.Abandon();
Upvotes: 2
Reputation: 9399
Page_Load (object sender, EventArgs e) {
if (!User.IsAuthenticated) {
Response.Redirect("login.aspx");
}
Also I'd have that in a the master page.
Upvotes: 2