我尝试使用本教程将自定义数据添加到MVC5身份验证中。 http://blog.falafel.com/customize-mvc-5-application-users-using-asp-net-identity-2-0/ 这很好用。 现在我想显示我已添加到管理配置文件页面的自定义字段。 您现在只能更改密码。 这是我的控制器,我试图获取用户信息:
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 userId = User.Identity.GetUserId();
//Here starts my error
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentUser = manager.FindById(User.Identity.GetUserId());
var model = new IndexViewModel
{
HasPassword = HasPassword(),
Logins = await UserManager.GetLoginsAsync(userId),
BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
};
return View(model);
}
通过var manager = new UserManager ...... 我收到了错误 命名空间的类型&#39; UserStore&#39;无法找到。 但这是MVC用于身份验证的标准命名空间。
我在这里遗漏了什么吗? 提前致谢
答案 0 :(得分:1)
如果我引入以下命名空间,该代码对我有用:
using Microsoft.AspNet.Identity.EntityFramework;
你能看出这是否可以解决你的问题?