---
title: "Forcibly logout all other sessions in case of multiple login by same user"  
description: "Forcibly logout all other sessions in case of multiple login by same user"  
author: "prarthana iyer"  
published: 2013-01-02  
updated: 2013-01-03  
canonical: https://www.mindstick.com/forum/522/forcibly-logout-all-other-sessions-in-case-of-multiple-login-by-same-user  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Forcibly logout all other sessions in case of multiple login by same user

Hi

I have an [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) where in im [preventing](https://www.mindstick.com/news/2244/issue-preventing-users-from-accessing-facebook-s-social-networking-platforms-has-been-resolved) [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) login by same user.If user tries to login from another webpage/machine(when [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) logged in anolther) then a confirm box appears asking whether he needs to logout the [previous](https://yourviews.mindstick.com/view/81421/unlock-2-0-is-just-like-previous-corona-lockdowns) [session](https://www.mindstick.com/articles/12042/session-in-c-sharp) or not,if he clicks "yes" then the previous [sessions](https://answers.mindstick.com/qa/44945/where-do-i-get-information-on-the-sessions-of-lok-sabha) 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](https://www.mindstick.com/forum/2005/radio-button-redirect) user to main page with [present](https://answers.mindstick.com/qa/96635/explain-about-the-various-features-present-in-ms-access) session

He is the code

In loginButton_Click(after [authentication](https://www.mindstick.com/blog/177/authentication-and-authorization-in-asp-dot-net))

```
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

## Replies

### Reply by John Smith

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)

### Reply by prarthana iyer

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

### Reply by John Smith

What is the concept of multiple login and are you trying to maintain users session activity in database table?\


---

Original Source: https://www.mindstick.com/forum/522/forcibly-logout-all-other-sessions-in-case-of-multiple-login-by-same-user

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
