Próbuję opanować nowy system członkostwa wprowadzony w ASP.NET MVC 5 i natknąłem się na mały problem, z którego jestem pewien, że będziesz w stanie mi pomóc.Właściwości niestandardowe aplikacji użytkownika MVC5 ApplicationUser
ja jadę w oparciu off this tutorial i wprowadziły właściwości niestandardowych do ApplicationUser takie jak imię, nazwisko, DOB, itp
Jednak zamiast tworzyć użytkownikowi, staram się aktualizować aktualnie zalogowanego w jednym. Patrzę na metodę kontrolera, która jest obecnie używana do zmiany hasła.
public async Task<ActionResult> Manage(ManageUserViewModel model)
{
string userId = User.Identity.GetUserId();
bool hasLocalLogin = await IdentityManager.Logins.HasLocalLoginAsync(userId);
ViewBag.HasLocalPassword = hasLocalLogin;
ViewBag.ReturnUrl = Url.Action("Manage");
if (hasLocalLogin)
{
if (ModelState.IsValid)
{
IdentityResult result = await IdentityManager.Passwords.ChangePasswordAsync(User.Identity.GetUserName(), model.OldPassword, model.NewPassword);
if (result.Success)
{
return RedirectToAction("Manage", new { Message = "Your password has been changed." });
}
else
{
AddErrors(result);
}
}
}
else
{
// User does not have a local password so remove any validation errors caused by a missing OldPassword field
ModelState state = ModelState["OldPassword"];
if (state != null)
{
state.Errors.Clear();
}
if (ModelState.IsValid)
{
// Create the local login info and link it to the user
IdentityResult result = await IdentityManager.Logins.AddLocalLoginAsync(userId, User.Identity.GetUserName(), model.NewPassword);
if (result.Success)
{
return RedirectToAction("Manage", new { Message = "Your password has been set." });
}
else
{
AddErrors(result);
}
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
W jaki dokładnie sposób mam aktualizować nazwę użytkownika ApplicationUser? Czy muszę wywołać DbContext lub?
Mam nadzieję, że moje pytanie jest jasne.
+1 Możesz użyć CancellationToken.None z System.Threading zamiast tworzyć jedną BTW. – Stimul8d
Niesamowici faceci! Dzięki – teh0wner