1

Essentially I am asking this question here, but I am using ASP Identity instead of the ASP.Net Membership provider, and with that, that answer is of no use to me.

Community
  • 1
  • 1
GregoryHouseMD
  • 2,168
  • 1
  • 21
  • 37
  • http://stackoverflow.com/questions/2922502/limit-only-one-session-per-user-in-asp-net – Michael B. Aug 18 '14 at 09:26
  • possible duplicate of [When the same user ID is trying to log in on multiple devices, how do I kill the session on the other device?](http://stackoverflow.com/questions/15903574/when-the-same-user-id-is-trying-to-log-in-on-multiple-devices-how-do-i-kill-the) – Simon Halsey Aug 18 '14 at 09:32
  • 1
    The answer you referenced is pretty much what you need to do. The references to Membership are minimal & you should easily be able to change them to Identity. – Simon Halsey Aug 18 '14 at 09:33
  • 1
    Turns out you are right, but after a few more hours digging, i found [this](http://stackoverflow.com/questions/19487322/what-is-asp-net-identitys-iusersecuritystampstoretuser-interface). Won't this help with the situation without any database manipulation? – GregoryHouseMD Aug 18 '14 at 16:44

1 Answers1

0

Figured out how to do it. On login I call this:

var key = user.UserName;
var timeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
HttpContext.Current.Cache.Insert(key, Session.SessionID, null, DateTime.MaxValue, timeOut, CacheItemPriority.NotRemovable, null);

And this in the Global.asax

if (Session["username"] != null)
    {
        var cacheKey = Session["username"].ToString();
        if ((string) HttpContext.Current.Cache[cacheKey] != Session.SessionID) LogOut();
    }
GregoryHouseMD
  • 2,168
  • 1
  • 21
  • 37