How to end the user session and make sure that the user is logged out?

元气小坏坏 提交于 2019-12-06 04:30:50

问题


I am new to .aspx and now the thing is since i am doing a web enabled project, I have this login from an user. I drag dropped the login template and then used the

Session["Authentication"] = username.Tostring();

to store the current logged user's info and so. Now i even used a hyperlink "Logout" at the top right corner and then made it transfer to Login page. ( If this is wrong way of transfering Please Let me know, I am Learning all by internet)..

Now if on running the web , i can easily login , but when i logout through hyper link "logout" it will take me to the Login page again, but if i press the back button of the browser it again transfers the control to the data page and i can again perform the data operation's.

I used this

Session["Authenticate"] = null

at the page load of the login page so that only at the login button click the user can enter again by

Session["Authenticate"] = username.Tostring();

Then i used a check at each page load of the data pages

if(Session[Authentiacte"] == null)
     Server.Tranfer("LoginPage.aspx");

This didnt solve my problem, Please can anyone give a hint or a link or a tip to improve my way of logout? I strated this project without any knowledge of the .net or aspx and i am still learning everything, please bare my doubts thankx in advance..


回答1:


HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();
HttpContext.Current.User = null;
System.Web.Security.FormsAuthentication.SignOut(); // if forms auth is used


来源:https://stackoverflow.com/questions/3359833/how-to-end-the-user-session-and-make-sure-that-the-user-is-logged-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!