How to add new properties to a user using Identity?

4

How can I create new properties using the UserIdentity that comes by default when creating an MVC 5 application?

Also, is it interesting to put information that does not pertain directly to authentication and authorization in the UserIdentity class?

On my system, in addition to the user profile information, it will have a shopping cart, an address list, and a move. Should this information be in the same UserIdentity?

I am using EntityFramework CodeFirst with DataAnnotations.

    
asked by anonymous 30.06.2014 / 03:10

1 answer

2

How can I create new properties using the UserIdentity that comes by default when creating an MVC 5 application?

Extending the class IdentityUser . For example:

public class ApplicationUser : IdentityUser
{
    [Required]
    public string FirstName { get; set; }

    [Required]
    public string LastName { get; set; }

    [Required]
    public string Email { get; set; }
}

Also, is it interesting to put information that does not pertain directly to authentication and authorization in the UserIdentity class?

Yes. It all depends on the needs of your system. There is no problem in adding any properties you deem necessary for the proper functioning of your system.

In my system, in addition to the user profile information, it will have a shopping cart, an address list, and a move. Should this information be in the same UserIdentity?

The best way to do this is to create another Model that references the IdentityUser and has business features in it. This is due to the fact that IdentityUser does not necessarily work in sync with the main context of your Entity Framework application, which would require more custom code than you really need.

There is an article in CodeProject where this is widely discussed , even with some code in GitHub.

    
30.06.2014 / 03:49