Reputation: 164
I try to add custom data to the MVC5 authentication with this tutorial. http://blog.falafel.com/customize-mvc-5-application-users-using-asp-net-identity-2-0/ This works fine. Now i want to show the custom field i have added to the manage profile page. Here you can only change the password now. This is my controller where i try to get the user information:
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);
}
By var manager = new UserManager...... I get the error The type of namespace 'UserStore' could not be found. But this is a standard namespace MVC uses for there authentication.
Am i missing something here? Thanks in advance
Upvotes: 0
Views: 185
Reputation: 2504
That code works for me if I bring in the follow namespace:
using Microsoft.AspNet.Identity.EntityFramework;
Can you see if that resolves your problem?
Upvotes: 1