public async Task <IActionResult> Register(RegisterViewModel viewModel) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = viewModel.Email, Email = viewModel.Email, City = viewModel.City }; var result = await userManager.CreateAsync(user, viewModel.Password); if (result.Succeeded) { var token = await userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme); logger.Log(LogLevel.Information, confirmationLink); messageServices.SendEmail(confirmationLink); if (signInManager.IsSignedIn(User) && User.IsInRole("Admin")) { return(RedirectToAction("ListUsers", "Administration")); } //await signInManager.SignInAsync(user, isPersistent: false); //return RedirectToAction("index", "home"); ViewBag.ErrorTitle = "Registration successful"; ViewBag.ErrorMessage = "Before you can Login please confirm your email, by clicking on the confirmation link we have emailed to you"; return(View("Error")); } foreach (IdentityError error in result.Errors) { ModelState.AddModelError("", error.Description); } } return(View(viewModel)); }