public ActionResult LoginOn(LoginModel model) { //判断验证是否通过 if (!ModelState.IsValid) { return(View()); } var Dmodel = userhandler.GetSingleByName(model.user_login_name); if (Dmodel == null) { ViewBag.Data = 1; return(View()); } //判断用户是否禁用,禁用提示信息 if (!Dmodel.isopen) { ModelState.AddModelError("user_login_name", "用户名不存在"); return(View()); } var str = MD5Helper.Decode(Dmodel.user_pwd); if (!str.Equals(model.user_pwd)) { ModelState.AddModelError("user_pwd", "密码不正确"); return(View()); } model.user_pwd = MD5Helper.Encode(model.user_pwd); var j = new { record = Dmodel }; JavaScriptSerializer serializer = new JavaScriptSerializer(); //response.Write(serializer.Serialize(Dmodel)); //保存身份信息,参数说明可以看提示 //string roles = "admin,member,developer"; FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, model.user_login_name, DateTime.Now, DateTime.Now.AddHours(2), false, Dmodel.user_role); HttpCookie Cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(Ticket)); //加密身份信息,保存至Cookie Cookie.HttpOnly = true; //客户端无法访问Cookie Response.Cookies.Add(Cookie); ViewBag.Data = 0; return(View()); }