5

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?

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Are you sure about this? The table is created with EF Code First and it's schema is checked against the migrations index. So how do you stop a conflict?\
1
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

Comments

0

The Visitor class is provided for you as a template when you setup a new Identity Framework project, and that class is tied to the AspNetUsers table. It inherits a bunch of properties you have weak/no control over, and then you can just add whatever you want.

public class Visitor : IdentityUser
{
    [MaxLength(300)]
    public string FirstName { get; set; }

    [MaxLength(300)]
    public string LastName { get; set; }

    public DateTime CreatedOn { get; set; }


    public Visitor()
    {
        CreatedOn = DateTime.UtcNow;
    }
}

I have not yet found a way to modify or even directly query the AspNetUserLogins table, as the default Identity Framework setup gives you a db with access to Users and Roles, but not Logins. Further the table is there as a step down from Users, but, that isn't going to let you query it. And, you're at least by default stuck with the stock class that comes with Identity Framework; subclassing it and getting the framework to use that subclass may be off the table. Don't know, worth its own question:

Add Columns/Properties to AspNetUserLogins/Logins in IdentityDbContext

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.