これは、そのユーザーのみが自分のパスワードを変更できるように、パスワードの変更で行う方法です。
私のアカウントコントローラーで
//
// GET: /Account/ChangePassword
[Authorize]
public ActionResult ChangePassword()
{
return View();
}
//
// POST: /Account/ChangePassword
[Authorize]
[HttpPost]
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
return RedirectToAction("ChangePasswordSuccess");
else
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
}
// If we got this far, something failed, redisplay form
return View(model);
}
次に、私の in _Layoutで、このように宣言して、そのユーザーのみがその ActionLink を表示して開き、自分のパスワードを変更できるようにします
@if (HttpContext.Current.User.Identity.IsAuthenticated)
{
<li>@Html.ActionLink("Change Password", "ChangePassword", "Account")</li>
}
これがあなたにも役立つことを願っています..乾杯。:)