1.在登陆方法中存储session、cookie值
public JsonResult Login(AdminUser adminUser,bool check)
{
Operate operate = new Operate();
AdminUser adminUsers = new AdminUser();
Expression<Func<AdminUser, bool>> lambdaExpression = a => a.Name == adminUser.Name && a.Password == adminUser.Password;
adminUsers = adminInfoService.Query(lambdaExpression);
operate.Success = adminUsers != null;
if (adminUsers != null)
{
operate.Success = true;
//存储session值
AdminContext.adminContext.adminInfo = adminUsers;
//如果选中保存密码则存储cookie
if (check)
{
//存储cookie
//创建一个Cookie对象
HttpCookie httpCookie = new HttpCookie("CookieName");
//设置Cookie的值
httpCookie.Values.Add("Name", adminUsers.Name);
httpCookie.Values.Add("Password", adminUsers.Password);
httpCookie.Values.Add("DateTime", DateTime.Now.AddDays(7).ToString("yyyy-MM-dd HH:mm:ss"));
//设置Cookie的过期时间
httpCookie.Expires = DateTime.Now.AddDays(7);
System.Web.HttpContext.Current.Response.Cookies.Add(httpCookie);
}
}
return Json(operate);
}
2.session存储的是对象,而提供的是没