I am using ASP.NET's built-in identities system. And I want to have different types of users. ASP.NET already allows me to create user roles, but I also want to store different types of data depending on which role the user has.
For example, a customer can have a balance, while a supplier can have a company name. But both are users which should be able to log into my system. Is there a good way to do this in ASP.NET?
答案 0 :(得分:0)
Use the asp.net identity profile API to add custom properties for your users.
public class ApplicationUser : IdentityUser
{
// start custom properties
public string HomeTown { get; set; }
public System.DateTime? BirthDate { get; set; }
// end custom properties
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;
}
}
This post from the asp.net team has a more step by step approach.