protected void CreateUser_Click(object sender, EventArgs e)
 {
     string userName = UserName.Text;
     var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
     ApplicationUser u = new ApplicationUser() { UserName = userName };
     IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
     if (result.Success) 
     {
         manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
         OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
     }
     else 
     {
         ErrorMessage.Text = result.Errors.FirstOrDefault();
     }
 }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Create a local login before signing in the user
                var user = new ApplicationUser() { UserName = model.UserName, Points = 10 };
                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }