问题
I am using the new user authentication system Asp.Net Identity in my project. I have a situation where I have to store 3 types of users in database i.e.:
- Student
- Teacher
- Admin
Now all these 3 have there separate table contains different information about each one of them. I want Asp.Net Identity to handle their login, logoff and password maintance for each type of user.
Can anyone please guide me with the overview of how can I handle this situation?
回答1:
You need an inheritance structure like this:
public abstract class User {}
public class Student : User {}
public class Teacher : User {}
public class Admin : User {}
where the User base class holds all necessary info for authentication. This way, you can handle all types of Users in a unified way.
Regarding the database, there are various strategies how such polymorphism can be handled (e.g. Table per Concrete Type).
回答2:
Here's what I just thought :
First of all, in your database make a table named "Roles", which will contains all your roles, as you mentioned in your post ( Student, Teacher, Admin and so on )
Then put a foreign key in your tables ( RoleId )
Make your custom membership provider
I think this should work
来源:https://stackoverflow.com/questions/20716711/how-to-do-handle-login-logoff