protected void DoLogin(ENT.Member member, bool chkIsRemember) { Session[SessionKeys.MemberInfo] = new SessionUser() { Id = member.Id, NickName = member.NickName, Name = member.Name, SurName = member.Surname, Email = member.Email }; CrpytorEngine crp = new CrpytorEngine() { SecurityKey = SessionKeys.Cookie_MemberId }; var httpCookie = new HttpCookie(SessionKeys.CookiePrefix); httpCookie.Values.Add(new NameValueCollection { {SessionKeys.Cookie_MemberId,crp.Encrypt(member.Id.ToString(),true).ToString(CultureInfo.InvariantCulture)} }); httpCookie.Path = "/"; httpCookie.Secure = false; httpCookie.Expires = chkIsRemember ? DateTime.Now.AddDays(7) : DateTime.MinValue; Response.SetCookie(httpCookie); }
public override void OnActionExecuting(SWM.ActionExecutingContext filterContext) { if (HttpContext.Current.Session[SessionKeys.MemberInfo] == null) { IMemberBusiness memberBusiness = (IMemberBusiness)SWM.DependencyResolver.Current.GetService(typeof(IMemberBusiness)); var httpCookie = HttpContext.Current.Request.Cookies[SessionKeys.CookiePrefix]; if (httpCookie != null && httpCookie.Values[SessionKeys.Cookie_MemberId] != null) { string value = httpCookie.Values[SessionKeys.Cookie_MemberId]; CrpytorEngine crp = new CrpytorEngine() { SecurityKey = SessionKeys.Cookie_MemberId }; var memberId = int.Parse(crp.Decrypt(value, true)); var resultSet = memberBusiness.GetMemberByMemberId(memberId); if (resultSet.Success) { HttpContext.Current.Session[SessionKeys.MemberInfo] = new SessionUser() { Id = resultSet.Object.Id, NickName = resultSet.Object.NickName, Name = resultSet.Object.Name, SurName = resultSet.Object.Surname }; } } } if (HttpContext.Current.Session[SessionKeys.MemberInfo] == null) filterContext.Result = new SWM.RedirectResult(string.Format("/{0}/{1}", RouteKeys.MemberController, "Index"), false); base.OnActionExecuting(filterContext); }