I changed over to use the new ASP.NET Identity 2. I'm actually using the Microsoft ASP.NET Identity Samples 2.0.0-beta2.
Can anyone tell me where and how I can modify the code so that it stores a user First and Last name along with the user details. Would this now be part of a claim and if so how could I add it ?
I assume I would need to add this here which is the register method in the account controller:
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
ViewBag.Link = callbackUrl;
return View("DisplayEmail");
}
AddErrors(result);
}
Also if I did add the first and last names then where is this stored in the database? Do I need to create an additional column in a table for this information?
I realize this post is a few years old, but with ASP.NET Core gaining traction I ended up here having a similar question. The accepted answer recommends you update your user data model to capture this data. I don't think that it's a bad recommendation, but from my research claims is the correct way to store this data. See What is the claims in ASP .NET Identity and User.Identity.Name full name mvc5. The latter is answered by someone from the ASP.NET Identity team at Microsoft.
Here is a simple code sample showing how you add those claims using ASP.NET Identity:
You'll need to add it to your
ApplicationUser
class so if you use Identity Samples, I imagine you have something like that in yourIdentityModels.cs
after adding First and Last Names it would look like this:
Then when you register user, you need to add them to the list now that they are defined in
ApplicationUser
classfirst and last names will end up in
AspNetUsers
table after you do the migrations