管理用户在ASP.NET页面的访问 [英] Manage user access to pages in ASP.NET
问题描述
我使用的MembershipProvider,目前一个有3个作用:
用户,超级用户,管理员。
I am using MembershipProvider and currently a have 3 roles: User, Super User, Admin.
我也有,只能由管理员和超级用户可以看到的页面。
对于这些网页中的web配置一个我使用的配置:
Also I have pages that can be seen only by Admin and Super User. For these pages a I use configuration in web config:
<location path="Users.aspx">
<system.web>
<authorization>
<allow roles="Admin, Super User"/>
<deny users="*" />
</authorization>
</system.web>
</location>
和这工作完全正常。
但我有一大堆的页面
Evaluations
Actions
Reports
Files
我想要独立访问权限的。我想授予访问每个单独的页面。
to which a I want separate access. I want grant access to each page individually.
有没有更好的方式来做到这一点不是每个页面创建角色,比分配到这些角色?
Is there better way to do it than create roles for each page and than assign to these roles?
P.S。
我使用ASP.NET,而不是MVC
P.S. I am using ASP.NET, not MVC
推荐答案
是的,修改文件夹结构是这样的:
Yes, modify your folder structure to be something like this:
- Super User
- Admin
- All
然后你就可以做的东西是这样的:
And then you can do stuff like this:
<location path="Super User">
<system.web>
<authorization>
<allow roles="Super User"/>
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="Super User/Admin">
<system.web>
<authorization>
<allow roles="Admin"/>
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="Super User/Admin/All">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
而现在只需将相应的文件夹页。按照 MSDN文档位置元素适用于所有子目录:
And now simply place the pages in the appropriate folders. Per the MSDN Documentation the location element applies to all sub-directories:
指定包含配置设置应用于资源。使用的位置,缺少路径属性适用的配置设置到当前目录及其所有子目录。如果位置用于没有道路属性,有的allowOverride为False,配置设置不能被认为是子目录Web.config文件中改变。
Specifies the resource that the contained configuration settings apply to. Using location with a missing path attribute applies the configuration settings to the current directory and all child directories. If location is used with no path attribute and allowOverride is False, configuration settings cannot be altered by Web.config files that are in child directories.
所以超级用户
定义将有机会获得以下等所有其他网页。
so Super User
by definition will have access to all other pages below and so on.
这篇关于管理用户在ASP.NET页面的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!