how to really logout in asp.net
41,619
Solution 1
I found a solution that I use in my master page
if (Membership.GetUser() != null)
.....
else Response.Redirect("Login.aspx")
and codebehind for logout button:
FormsAuthentication.SignOut();
Response.Redirect("Login.aspx");
Thanks for your help!
Solution 2
use FormsAuthentication.SignOut();
as below:
protected void LogoutButton_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("~/Login.aspx");
}
Solution 3
Use Session.Clear()
like this:
protected void Button_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("Login.aspx");
}
Solution 4
None worked for me but this does.
Context.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
Solution 5
The home webpage is loading from the browser cache, use the below metadata tags to force the browser to clear cache after exiting the page
<head runat="server">
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="cache-control" content="must-revalidate" />
<meta http-equiv="cache-control" content="proxy-revalidate" />
Author by
mirza
Updated on February 04, 2022Comments
-
mirza about 2 years
I use LoginControl for login into my website in asp.net, but when for logout use login status or session.Abandon or .sign out ,there's white backspace, my homepage is loaded and its not secure.
Please help me that use realy logout in my project.
-
mirza over 10 yearsi try it but when enter backspace my home page is loaded
-
Malachi over 9 yearsThis doesn't work if you use the same master page for Login.aspx, it will cause an infinite redirect loop, which is really bad.