【发布时间】:2014-12-01 16:02:11
【问题描述】:
我一直在关注本教程的将配置文件数据添加到用户类部分,以便在 MVC 5 中向我的注册页面添加更多字段。到目前为止,它工作正常,我没有任何问题。现在的问题是我不确定它是如何显示在“管理”页面上的,用户可以在其中看到他的个人资料信息,比如更改他的密码。例如,我想在该页面上添加名字和姓氏。
这是我正在谈论的页面的屏幕截图: http://puu.sh/dcMmj/82ddd8fc97.PNG
我的项目是 Visual Studio 为您创建的项目,并在注册页面中添加了名字和姓氏。在下面的身份模型中添加了这个,就像在教程中一样
public class ApplicationUser : IdentityUser
{
public string FirstName{ get; set; }
public string LastName { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
我想我需要在 ManageController.cs 中添加一些内容,但我不确定。
// GET: /Manage/Index
public async Task<ActionResult> Index(ManageMessageId? message)
{
ViewBag.StatusMessage =
message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
: message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
: message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
: message == ManageMessageId.Error ? "An error has occurred."
: message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
: message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
: "";
var model = new IndexViewModel
{
HasPassword = HasPassword(),
PhoneNumber = await UserManager.GetPhoneNumberAsync(User.Identity.GetUserId()),
TwoFactor = await UserManager.GetTwoFactorEnabledAsync(User.Identity.GetUserId()),
Logins = await UserManager.GetLoginsAsync(User.Identity.GetUserId()),
BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(User.Identity.GetUserId()),
// I think it goes in here somewhere
};
return View(model);
}
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-mvc-5