0

When i click on logout button it didn't redirect to Login_Form.aspx page

protected void Logout_button_Click(object sender, EventArgs e)
{
    Session.Abandon();
    Session.Clear();
    Session.Remove("LoginUserName");
    Server.Transfer("Login_Form.aspx");
}

<Button ID="_Logout_Button" class="btn btn-danger fa fa-power-off" runat="server"  onClick="Logout_button_Click" />
Fábio Nascimento
  • 2,644
  • 1
  • 21
  • 27
Nadir Ali
  • 1
  • 2
  • What type of authentication are you using? Forms? – DBro Apr 29 '19 at 17:02
  • Form authentication – Nadir Ali Apr 29 '19 at 17:03
  • `FormsAuthentication.SignOut();` `FormsAuthentication.RedirectToLoginPage();` – DBro Apr 29 '19 at 17:03
  • Sir i want to do it without using asp.net built-in functions. – Nadir Ali Apr 29 '19 at 17:04
  • 1
    Try `Response.Redirect("~/Login_Form.aspx");` instead of Server Transfer – dvo Apr 29 '19 at 17:05
  • @NadirAli Take a look at the accepted answer on this SO post (https://stackoverflow.com/questions/412300/formsauthentication-signout-does-not-log-the-user-out), it appears there may be a bug (or intended behavior) with `Session.Abandon()` and `FormsAuthentication.SignOut()` that doesn't clear the authentication cookie from the browser. Basically it looks like the answer is to set the expiration on the cookies to a past date and time. – Ryan Wilson Apr 29 '19 at 17:07
  • Ryan Wilson Sir thanks – Nadir Ali Apr 29 '19 at 17:16
  • @NadirAli You're welcome. Hope it helps, if so, please let me know. – Ryan Wilson Apr 29 '19 at 17:29
  • @rayn Wilson sir i am unable to solve this issue and i am not want to use asp.net built-in form authentication methods.pleas help me – Nadir Ali Apr 29 '19 at 20:28
  • In each page i also storing the session of user but when i tries to redirect from one page to another it's also through an error that redirect link in not available. Please help me . – Nadir Ali Apr 29 '19 at 20:30
  • In `Asp.Net` *having a Session* and *being logged in* are separate things. If you are using `forms authentication` to handle user login, you'll need to use it for handling user logout as well. – user1429080 Apr 30 '19 at 09:20

0 Answers0