private void CreateUser(String email, String password, TravelAgencyService service, Action createUser) { List <String> errorList = new List <string>(1); bool isSuccess = false; // Attempt to register the user if (WebDataHelper.CreateAccount(email, password, errorList)) { try { createUser(); service.Save(); WebSecurity.Login(email, password); isSuccess = true; } catch (Exception ex) { HandleRegistrationError(email, ex); } } else { ModelState.AddModelError("", "E-mail is already in use."); } // Warning: Redirect to URL throws special exception which must not be handled. // Whne it is handled in above try then the newly created account is deleted. if (isSuccess) { RedirectHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); } }
protected void LogIn(object sender, EventArgs e) { if (IsValid) { if (WebSecurity.Login(LoginTextBox.Text, Password.Text, persistCookie: RememberMe.Checked)) { WebDataHelper.AddUserToRole(LoginTextBox.Text); RedirectHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); } else { ModelState.AddModelError("", "Login failed."); } } }