【发布时间】:2013-06-07 11:29:55
【问题描述】:
我想禁用多重登录到我的网站。
所以我正在缓存中创建一个会话。
并且我在登录之前检查会话是否已经存在于缓存中,如果不是,我正在创建一个会话并允许他登录。 如果会话已经存在,我将抛出一条错误消息,表明您已在其他地方登录。
我正在注销中清除本地和缓存会话。一切正常,但是当页面因不活动而过期时,本地会话将被删除,但缓存中的会话保持不变。所以即使我尝试从同一个浏览器登录,它也会给出错误,因为我已经登录了。
这是我的代码 在 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;
允许登录 } 别的 { 或错误信息 }
请告诉我如何同时使这两个东西过期。
【问题讨论】:
标签: c# asp.net session caching login