Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add fields to the AspNetUsers table in Asp.Net Identity Framework?

I am exploring the new asp.net identity. Adding fields to the Users table "AspNetUsers" using code-first and migration features seems great.

I want to add columns like "Name", "CreatedOn", and "CreatedFromIP" and be able to read it from .NET

Is there a simple solution?

like image 449
Bassel Banbouk Avatar asked Sep 30 '22 19:09

Bassel Banbouk


2 Answers

You can simply open the database from App_Start folder and modify the fields. (In case your using the template)

like image 81
Xtian Avatar answered Oct 10 '22 21:10

Xtian


public class ApplicationUser : IdentityUser
{
    public string YourProperyHere { 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;
    }
}

Read more here

like image 36
Archil Labadze Avatar answered Oct 10 '22 19:10

Archil Labadze