コード例 #1
0
        public ActionResult Login(LoginViewModel model,string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = _repository.Users.FirstOrDefault(item => item.Username.ToLower() == model.Username.ToLower() && item.Password == model.Password);

                if (user == null || user.Password != model.Password)
                {
                    ModelState.AddModelError("","The Username or password id correct");
                    return View(model);
                }

                FormsAuthentication.SetAuthCookie(model.Username, false);

                Session["User"] = user;

                if (!string.IsNullOrEmpty(returnUrl) && returnUrl !="/Product/ViewDetails")
                {
                    return Redirect(returnUrl);
                }

                return RedirectToAction("List", "Product");
            }
            return View(model);
        }
コード例 #2
0
        public ViewResult Login(string returnUrl)
        {
            var model = new LoginViewModel {Username = string.Empty, Password = string.Empty, returnUrl = returnUrl};
            Session["User"] = null;

            return View(model);
        }