簡體   English   中英

每個用戶僅允許一個登錄會話

[英]Allow only a single login session per user

本質上,我在這里這個問題 ,但是我使用的是ASP Identity而不是ASP.Net Membership提供者,因此,這個答案對我沒有用。

想通了如何做。 登錄時,我稱其為:

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);

而這在Global.asax

if (Session["username"] != null)
    {
        var cacheKey = Session["username"].ToString();
        if ((string) HttpContext.Current.Cache[cacheKey] != Session.SessionID) LogOut();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM