How to do handle login-logoff

时间秒杀一切 提交于 2020-01-03 02:30:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!