简体   繁体   English

asp.net c#用户登录访问和授权以及菜单

[英]asp.net c# user login access and authorization and menu

I am working on web application and I have 3 types of users. 我正在开发Web应用程序,并且我有3种类型的用户。 As we know different users have different access rights. 众所周知,不同的用户具有不同的访问权限。 Suppose there are three users A,B,C. 假设有三个用户A,B,C。

And there are total of 5 menus, example menu1,menu2.menu3,menu4,menu5. 共有5个菜单,例如menu1,menu2.menu3,menu4,menu5。

I have to set access rights like 我必须设置访问权限,例如

User A can access menu1,menu2.menu3,menu4,menu5. 用户A可以访问menu1,menu2.menu3,menu4,menu5。

User B can access menu2.menu3. 用户B可以访问menu2.menu3。

User C can access menu3,menu4,menu5. 用户C可以访问menu3,menu4,menu5。

In this I may add one more user having different access rights. 在此,我可以再添加一个具有不同访问权限的用户。

My question is how I design database and what logic I should apply to get this result. 我的问题是我如何设计数据库以及应采用什么逻辑来获得此结果。

I have one solution but I am trying it through the database. 我有一个解决方案,但我正在通过数据库进行尝试。 That solution is to keep different master pages for different users but that's not a good solution. 该解决方案是为不同用户保留不同的母版页,但这不是一个好的解决方案。

From login identify users access level. 通过登录标识用户访问级别。 Inside master page have different regions for user levels 母版页中的用户级别具有不同的区域

Reffer this - 引用此-

how to make masterPage contents visible based on role? 如何根据角色使masterPage内容可见? [a similar question] [类似的问题]

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginview.rolegroups%28v=vs.110%29.aspx [A good guide] http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.loginview.rolegroups%28v=vs.110%29.aspx [良好指南]

-Happy Coding- -快乐编码-

There are so many ways to do this; 有很多方法可以做到这一点。 here is an example of what you can do: 这是您可以做什么的示例:

  • Put all menus in one masterpage 将所有菜单放在一个母版页中
  • On Session_Start get his access level from the database and store it in session variable 在Session_Start上,从数据库获取他的访问级别并将其存储在会话变量中
  • On masterpage Page_Load you can show and hide the menus based on the access level 在主页Page_Load上,您可以根据访问级别显示和隐藏菜单

I am assuming that you are only having Five menu's. 我假设您只有五个菜单。 You can do something like this. 你可以做这样的事情。

As per My knowledge first you need to insert the information in to the database for your access control. 据我所知,首先需要将信息插入数据库中以进行访问控制。 So you can do some thing like this to insert values into the database for access control. 因此,您可以执行类似的操作以将值插入数据库以进行访问控制。

User        Menu-1        Menu-2      Menu-3     Menu-4    Menu-5

A             1             1           1          1         1

B             0             1           1          0         0                 

C             0             0           1          1         1

you can Use Repeater or Grdiview to display UI like above. 您可以使用Repeater或Grdiview来显示上面的UI。

0 & 1 are nothing but the checkboxes . 0和1 只是复选框

0- Means checkbox is not checked & user cannot access that menu
1- Means checkbox is checked & user can access that menu

Table Structure 表结构

Create Table User_Details
(
  UserId int identity(1,1)
  UserName varchar(100),
  menu1 bit,
  menu2 bit,
  menu3 bit,
  menu4 bit,
  menu5 bit
)

This was about the inserting information into the database regarding your database. 这与将有关数据库的信息插入数据库有关。

Now for Access Control you can Do :

I am assuming that you have used User control for your menu. 我假设您已将User control用于菜单。

If your user is logged in then you will have ID of the user and In all the page of your menu (User Control) you need to check that is your user has access to that particular Menu 如果您的用户已登录,那么您将拥有该用户的ID ,并且在菜单的所有页面(用户控制)中,需要检查用户是否有权访问该特定菜单

IF YES : then You can make your panel of the menu visible for that user IF YES :那么您可以使该菜单的面板对该用户可见

IF NO : then You have to your panel of the menu invisible for that user IF NO :那么您必须在菜单面板中对该用户不可见

For object oriented approach and efficiency when it comes to data manipulation. 面向对象的方法和数据处理效率。
Create 2 tables: t_Users and t_Types 创建2个表: t_Userst_Types
t_Types have columns like (ID, roles) roles will be your access type, (ex. admin, normal user) t_Type具有类似(ID,role)的,角色将是您的访问类型,(例如admin,普通用户)
t_Users have columns like (ID, Name, TypeID) where TypeID is a foreign key for you to assign what kind of user does the user belong. t_Users具有(ID,Name,TypeID)之类的列其中TypeID是外键,供您分配用户所属的用户类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM