Ich habe ein MVC 5 Projekt auf MVC 6 umgestellt und habe Probleme mit dem Identity Management.Identity Management in MVC 6
Als Teil des Anmeldevorgangs wählt der Benutzer eine Rolle aus, die mithilfe von ApplicationUserManager in einer UserRoles-Tabelle gespeichert wird.
In der MVC-5-Version, ist der Code in meinem AccoutnControler
public ApplicationUserManager UserManager {
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
später auf die in der Steuerung ...
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, IsRegComplete = true};
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
UserManager.AddToRole(user.Id, model.Role);
await SignInAsync(user, isPersistent: false);
if (model.Role == "Owner")
{
return RedirectToAction("Create", "Owners");
}
else
{
return RedirectToAction("Create", "ServiceCompanies");
}
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
Da es keine IdentityConfig.cs in MVC ist 6, wo tut der ApplicationUserManager oder was ersetzt es, um mir AddToRole() zu erlauben?
Prost, Kevin.
Dies ist eher ein Kommentar als Antwort –