我想禁用我的网站中的多帐户。
所以我在缓存中创建一个会话。
我在登录前检查如果会话已经存在于缓存中,如果不是我正在创建会话并允许他登录。 如果会话已经存在,我会抛出一条错误消息,告知您在其他地方登录。
我正在清除注销中的本地和缓存会话。一切正常,但当页面因不活动而过期时,本地会话将被删除,但缓存中的会话保持不变。所以即使我试图从同一个浏览器登录它的错误,因为我已经登录。
这是我的代码 在global.asax
中 if (HttpContext.Current.Session != null &&
HttpContext.Current.Session["MULTIPLELOGIN"] != null)
{
string sKey = Session["MULTIPLELOGIN"].ToString();
string sRecruiter = HttpContext.Current.Cache[sKey].ToString();
}
登录
string sKey = oRecruiter.RecruiterId.ToString();
string sRecruiter = Convert.ToString(HttpContext.Current.Cache[sKey]);
if (sRecruiter == null || sRecruiter == String.Empty)
{
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);
HttpContext.Current.Session["MULTIPLELOGIN"] = userid;
允许登录 } 其他 { 或错误消息 }
请让我知道如何同时使两件事过期。
答案 0 :(得分:0)
提供缓存过期时间和会话时间相同,这可能会解决您的问题
答案 1 :(得分:0)
我找到了答案 将cacheitempriority更改为SessTimeOut,System.Web.Caching.CacheItemPriority.Normal from NotRemovable