Home > DeveloperSection > Forums > Forcibly logout all other sessions in case of multiple login by same user
prarthana iyer
prarthana iyer

Total Post:1

Points:7
Posted on    January-02-2013 5:02 AM

 ASP.Net ASP.Net 
Ratings:


 3 Reply(s)
 2345  View(s)
Rate this:

Hi

I have an application where in im preventing multiple login by same user.If user tries to login from another webpage/machine(when already logged in anolther) then a confirm box appears asking whether he needs to logout the previous session or not,if he clicks "yes" then the previous sessions shud be logged off.Im not able to logout the previous session however the code is preventing multiple login but how can i logoff the previous session n redirect user to main page with present session

He is the code

In  loginButton_Click(after authentication)

string sKey = loginControl.UserName + loginControl.Password;

string sUser = Convert.ToString(Cache[sKey]);

if (sUser == null || sUser == String.Empty||sUser=="")

{

TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);

HttpContext.Current.Cache.Insert(sKey, sKey, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null);

Session["user"] = loginControl.UserName + loginControl.Password;

Response.Redirect("MainPage.aspx");

}

else

{

Response.Write("<script>if(window.confirm('You have already Logged In.Do you want to sign off the previous Session?')){} else{window.location.href='login.aspx'}</script>");

return;

}

 

In Global.aspx page

//==========================================

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)

{

if (System.Web.HttpContext.Current.Session != null)

{

if (Session["user"] != null)

{

string sKey = (string)Session["user"];

string sUser = (string)HttpContext.Current.Cache[sKey];

}

else

{

foreach (DictionaryEntry de in HttpContext.Current.Cache)

{

HttpContext.Current.Cache.Remove((string)de.Key);

}

}

}

}

Please Guide

Regards

Prarthana Iyer

 

 



John Smith

Total Post:102

Points:720
Posted on    January-02-2013 1:11 PM

What is the concept of multiple login and are you trying to maintain users session activity in database table?

prarthana iyer
prarthana iyer

Total Post:1

Points:7
Posted on    January-02-2013 10:57 PM

Multiple Login (By same user)

User already logged in a machine/browser and tries to re-login from another machine/browser(with same userid n password) .

user's session activity in Db

I had tot abt this ,however dint implement,got the above code for preventing multiple login but im unable to logoff the user's previous session


John Smith

Total Post:102

Points:720
Posted on    January-03-2013 10:53 AM

Add a column in your database table with the name of "LoginStatus" use bit operator ... if user successfully logged on then update "LoginStatus" True .
Before logon you will have to check column value (If user loginstatus is true then ask him to logout or continue)

Don't want to miss updates? Please click the below button!

Follow MindStick