问题
I have a asp.net web application login page which has buil-in Authentication of asp.net and login.aspx page created by Login control of asp.net. Now i have a problem in logout.
When user pressed "Logout" the link is redirected to "Login.aspx" page. But, when the user press "Back" button from the browser the user "Login"to the page to the application which i want to avoid and it must ask to enter Login Credentials.
Help Appreciated..! Thanks in Advace..!
回答1:
you can try
protected void btnLogout_Click(object sender, EventArgs e)
{
Session.RemoveAll();
Session.Abandon();
Response.Redirect("LoginPage.aspx");
}
回答2:
Use the following code:
Session.RemoveAll();
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
回答3:
If you are using MasterPage
then in the Code Behind of your MasterPage, you can do this
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Expires = -1500;
Response.CacheControl = "no-cache";
Also do not forget to clear the Session while Logging off.
来源:https://stackoverflow.com/questions/9766804/how-to-kill-the-session-of-user-when-he-loggedout-in-asp-net