Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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..

like image 995
Nagaraj Tantri Avatar asked Dec 29 '22 09:12

Nagaraj Tantri


1 Answers

HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();
HttpContext.Current.User = null;
System.Web.Security.FormsAuthentication.SignOut(); // if forms auth is used
like image 80
abatishchev Avatar answered Jan 13 '23 14:01

abatishchev