使用Application改变用户在线状态
public List<UserStatus> SetUserStatus(string userAccount,string userName, string status, List<UserStatus> UserStatus) { #region 更改状态 //根据用户名查找,在application中更改对应的状态。 var query = UserStatus.Where(qu => qu.Account == userAccount); UserStatus temp = new DYModel.UserStatus(); if (query.Count() > 0) { temp = query.FirstOrDefault(); UserStatus.Remove(temp); } else { temp.Account = userAccount; temp.Name = userName; } temp.status=status; UserStatus.Add(temp); #endregion return UserStatus; }
protected void Session_End(object sender, EventArgs e) { //改变用户状态 UserInfo userInfo = (UserInfo)Session["SESSION_USER_MODEL_KEY"]; List<UserStatus> userStatus = (List<UserStatus>)Application["UserStatus"]; Application.Lock(); BLLUserStatus bll = new BLLUserStatus(); //修改为离线状态(可自行修改) Application["UserStatus"]=bll.SetUserStatus(userInfo.Account, userInfo.Name, "0", userStatus); Application.UnLock(); }