Ejemplo n.º 1
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager = new UserManager();
            var user    = new ApplicationUser()
            {
                UserName = UserName.Text
            };
            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                UserExtension.CreateRole();
                IdentityHelper.SignIn(manager, user, isPersistent: false);
                string userId = user.Id;
                Session["userId"] = userId;
                UserExtension.AddUserToRole(userId, "Customer");
                Response.Redirect("~/User/UserRegistration.aspx");
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }