/// <summary> /// 按需要跳转 /// </summary> /// <returns></returns> protected RedirectToRouteResult UserStatusRedirect() { //需要激活 //if (Kt.Framework.User.UserState.getIsNeedActived()) //{ // RouteValueDictionary routeData = new RouteValueDictionary(new { controller = "RegNav", Action = "Activateaccount", Area = "" }); // return RedirectToRoute(routeData); //} //在这里调用 if (!Kt.Framework.User.User.IS_LOGIN) { //RouteValueDictionary routeData = new RouteValueDictionary(new { controller = "RegNav", Action = "logOn", Area = "" }); //return RedirectToRoute(routeData); //在这里检验Cookie["ktweb_auth"]是否存在,是否没有过期,如果是,则更新用户登录状态,否则 if (Request.Cookies[UserCookies.SECURELOGIN] != null && Request.Cookies[UserCookies.SECURELOGIN].Expires < DateTime.Now) //if (Response.Cookies[UserCookies.SECURELOGIN] != null && Response.Cookies[UserCookies.SECURELOGIN].Expires < DateTime.Now) { //在这里让用户进行登录,调用Ucenter的方法将Cookies["ktweb_auth"].Value解码,然后拆出来uid,存入到记录用户登录状态的cookie中,以达到用户“免登录”的效果 //var cookievalue = Response.Cookies[UserCookies.SECURELOGIN].Value; var cookievalue = Request.Cookies[UserCookies.SECURELOGIN].Value; if (!string.IsNullOrEmpty(cookievalue)) { string userid = UserCookies.getSecureLoginCookies(UserCookies.AUTHCOOKIE_NAME_USERID); string logidId = UserCookies.getSecureLoginCookies(UserCookies.AUTHCOOKIE_NAME_USERNAME); string email = UserCookies.getSecureLoginCookies(UserCookies.AUTHCOOKIE_NAME_EMAIL); string nickname = UserCookies.getSecureLoginCookies(UserCookies.AUTHCOOKIE_NAME_NICKNAME); int expire = UserCookies.COOKIE_EXPIRETIME * 14; var uid = decimal.Parse(userid); //在这里设置最后登录状态 var oline = new UserOnline(); oline.AddUser(new UserInfo { LASTActive = DateTime.Now, Uid = uid }); UserCookies.setAuthCookies(uid, logidId, email, expire, nickname); //设置在线状态 Kt.Framework.User.User.Set_MEMBER_ID(uid); RouteValueDictionary routeData = new RouteValueDictionary(new { controller = "Index", Action = "Index", Area = "UserHome" }); return RedirectToRoute(routeData); } } else { RouteValueDictionary routeData = new RouteValueDictionary(new { controller = "RegNav", Action = "logOn", Area = "" }); return RedirectToRoute(routeData); } } return null; }
public static void Set_MEMBER_ID(decimal UID) { var oline = new UserOnline(); oline.AddUser(new UserInfo { Uid = UID, LASTActive = System.DateTime.Now }); //HttpContext.Current.Session[SessionKeys.UserID] = UID; }