I have created a different identity table MyUserInfo for my user profile where I store additional info such as Name, address etc. The idea is that if the user has not entered his / her data then he will be sent to another page where it can be done. The issue is that when I try to verify if the client has entered his name, address etc... i get an an error and I don't understand why:
Additional information: Object reference not set to an instance of an object.
this happens at the line where I try to check if the value of the User Name is null
if (currentUser.MyUserInfo.FirstName == null)
Here is the code:
string user = System.Web.HttpContext.Current.User.Identity.Name;
var store = new UserStore<ApplicationUser>(new ApplicationDbContext());
store.AutoSaveChanges = false;
var currentUserId = User.Identity.GetUserId();
var manager = new UserManager<ApplicationUser>(store);
var currentUser = manager.FindById(User.Identity.GetUserId());
//check if the user is registered and what his role is
if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated && System.Web.HttpContext.Current.User.IsInRole("Customer"))
{
if (currentUser.MyUserInfo.FirstName == null) //offending line
{
Response.Redirect("EnterUserData.aspx");
}
}