5

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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
mirza
  • 766
  • 2
  • 7
  • 12

5 Answers5

9

use FormsAuthentication.SignOut(); as below:

protected void LogoutButton_Click(object sender, EventArgs e)
{
    FormsAuthentication.SignOut();
    Response.Redirect("~/Login.aspx");
}
Habibillah
  • 27,347
  • 5
  • 36
  • 56
3

Use Session.Clear() like this:

protected void Button_Click(object sender, EventArgs e)
{
    Session.Clear();
    Response.Redirect("Login.aspx");
}
SharpC
  • 6,974
  • 4
  • 45
  • 40
Priya Gund
  • 156
  • 5
3

None worked for me but this does.

Context.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
Crismogram
  • 906
  • 15
  • 27
2

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" />

Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90
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!

erdekhayser
  • 6,537
  • 2
  • 37
  • 69
mirza
  • 766
  • 2
  • 7
  • 12
  • 2
    This doesn't work if you use the same master page for Login.aspx, it will cause an infinite redirect loop, which is really bad. – Malachi Dec 29 '14 at 17:59