[英]Allow only a single login session per user
想通了如何做。 登錄時,我稱其為:
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.