同时清除缓存和浏览器中的会话

本文关键字:会话 浏览器 清除 缓存 | 更新日期: 2023-09-27 18:17:33

我想禁用多重登录到我的网站。

所以我在缓存中创建一个会话。

和我在登录前检查,如果会话已经存在于缓存中,如果不是我正在创建一个会话,并允许他登录。如果会话已经存在,我抛出一个错误消息,你正在其他地方登录。

我正在清除签出中的本地和缓存会话。所有的工作都很好,但是当页面到期不活动时,本地的会话被删除,但缓存中的会话保持不变。因此,即使我试图从相同的浏览器登录它给出的错误,因为我已经登录。

这是我的代码在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;

允许登录}其他的{或者错误信息}

请告诉我如何同时过期。

同时清除缓存和浏览器中的会话

设置缓存过期时间和会话超时时间相同,这可能会解决您的问题

我找到了答案将cacheitempriority从NotRemovable

更改为SessTimeOut, system . web . cache . cacheitempriority . normal