コード例 #1
0
        public ActionResult SubmitLogin(Login model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (Membership.Provider.ValidateUser(model.UserName, model.Password))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, model.KeepMeLoggedIn);

                        //If the referring URL is the login page, then redirect the user to the my account page. Otherwise,
                        //send them back to the referrer
                        var redirectUrl = Request.UrlReferrer.AbsoluteUri.Contains("/login/") ? "/my-account/" : Request.UrlReferrer.AbsoluteUri;
                        return Redirect(redirectUrl);
                    }

                    ModelState.AddModelError("BadCredentials", "Bad user name or password.");
                }
                catch (Exception ex)
                {
                    LogHelper.Error(this.GetType(), "Login Error", ex);
                    ModelState.AddModelError("Error", "We are sorry, but the system encountered an error. Please try again.");
                }
            }

            return CurrentUmbracoPage();
        }
コード例 #2
0
 public ActionResult Login()
 {
     var model = new Login();
     return View(model);
 }