Cool Breeze
Cool Breeze

Reputation: 1369

Different profiles for different roles in Asp.net Identity.

Is it possible to have different profiles for different roles? or do I have to:

  1. Create a profile with all the fields that are shared i.e. First Name, Last Name.
  2. Create two separate tables that each include their own unique properties i.e. Table 1: DOB Table 2: Address and link to the profile?

Upvotes: 1

Views: 770

Answers (2)

jubair
jubair

Reputation: 597

You can use your identity user like this and then add a new Entity Teacher and Student:

public class User: IdentityUser
{
    [Required]
    [StringLength(100)]
    public string FirstName { get; set; }

    [Required]
    [StringLength(100)]
    public string LastName { get; set; }

    public DateTime JoinedOn { get; set; }
    public virtual Student Student { get; set; }

    public virtual Teacher Teacher { get; set; }

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
        UserManager<User, Guid> 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;
    } 
}

Upvotes: 1

jubair
jubair

Reputation: 597

You may Create different profile for different role. Suppose you have a User table and you have some roles like student, teacher, administrator. You can create a one to one relation between user and student, user and teacher, user and administrator. Attributes specific for Student keep those in Student table.

Edit1:

So you are right you can create the user with common attributes and other tables with attributes specific to them.

Upvotes: 0

Related Questions