I have a problem starting a new asp.net application. I choose asp.net mvc template with Individual User Accounts authentication and project generates and starts normally. My question is: what do i have to do to use register/login options? From what I understood methods responsible for these actions are generated automatically, but should I do something about database schema for information about users (shoudn't it be created also automatically?).
Anyway, after filling fields in register form i get error that a file couldn't be found and the error is found on line 155: var result = await UserManager.CreateAsync(user, model.Password);
I'm using Visual Studio Community 2015 on windows 8. Thank you in advance
public async Task<IActionResult> Register(RegisterVM registerVM)
{
if (!ModelState.IsValid)
{
return View();
}
AppUser appUser = new AppUser()
{
Fullname = registerVM.Fullname,
UserName = registerVM.Username,
Email = registerVM.Email
};
IdentityResult result = await _userManager.CreateAsync(appUser, registerVM.Password);
if (!result.Succeeded)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error.Description);
}
return View(registerVM);
}
await _userManager.AddToRoleAsync(appUser, Roless.Admin.ToString());
await _signInManager.SignInAsync(appUser, true);
return RedirectToAction("index", "home");
}
public IActionResult Login()
{
return View();
}
[HttpPost]
[AutoValidateAntiforgeryToken]
public async Task<IActionResult> Login(LoginVM loginVM, string returnurl)
{
if (!ModelState.IsValid)
{
return View();
}
AppUser dbUser = await _userManager.FindByEmailAsync(loginVM.Email);
if (dbUser == null)
{
ModelState.AddModelError("", "Ya email ya da Password sehvdir");
return View(loginVM);
}
SignInResult result = await _signInManager.PasswordSignInAsync(dbUser, loginVM.Password, loginVM.RememerMe, true);
if (result.IsLockedOut)
{
ModelState.AddModelError("", "Your Account Is Lock Out");
return View(loginVM);
}
if (!result.Succeeded)
{
ModelState.AddModelError("", "Ya Email ya da Password sehvdir");
return View(loginVM);
}
if (returnurl == null)
{
return RedirectToAction("index", "home");
}
foreach (var item in await _userManager.GetRolesAsync(dbUser))
{
if (item.Contains(Roless.Admin.ToString()))
{
return RedirectToAction("index", "Dashboard", new { area = "AdminF" });
}
}
return Redirect(returnurl);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.