public ActionResult Login(LoginModel model, string returnUrl) { //判断验证码是否正确 string validateCode = Session["code"] == null ? string.Empty : Session["code"].ToString(); if (string.IsNullOrEmpty(validateCode)) { return(Content("验证码不能为空")); } Session["code"] = null; string txtCode = Request["verifycode"].ToString(); if (!validateCode.Equals(txtCode, StringComparison.InvariantCultureIgnoreCase)) { return(Content("no:验证码输入错误")); } //用户登录,验证用户名和密码 是否正确 // if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) int userId = BLLUsers.ValidateUser(model.UserName, model.Password); if (ModelState.IsValid && userId > 0) { Session.Add("UserName", model.UserName); Session.Add("UserID", userId); return(RedirectToLocal(returnUrl)); } // 如果我们进行到这一步时某个地方出错,则重新显示表单 ModelState.AddModelError("", "提供的用户名或密码不正确。"); return(View(model)); }