如何在文件夹中添加基于角色的安全文件 [英] How add role based security the files in a folder
问题描述
我建立一个ASP.NET 3.5 Web应用程序,我没有使用安全的成员资格提供程序。在应用程序中我有一个名为管理角色和所有为这个角色的文件是在项目中的安全文件夹内。目前的安全文件夹内所有的页面,我检查,看看是否已登录用户的角色是管理员或没有。这对我来说似乎很多余的,可以做一些像如果用户要求的安全文件夹内的一个页面,然后检查了他的角色。这可能吗?
I am building an ASP.NET 3.5 Web Application and I am NOT using the membership provider for security. In the application I have a role named Admin and all the files for this role are inside the Security folder in the project. Currently for all the pages inside the security folder I am checking to see if the logged in user's role is an Admin or not. This to me seems very redundant, can do something like "If the user is requesting a page inside the security folder then check his role". Is this possible?
推荐答案
您可以放置在安全文件夹中一个单独的web.config文件,如果用户不在管理员角色,将拒绝访问每个请求到该文件夹
You can place a separate web.config file in the Security folder that will deny access to every request to that folder if the user isn't in the Admin role.
这将基本上是这样的:
<location path="Security">
<system.web>
<authorization>
<allow roles="Admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
这篇关于如何在文件夹中添加基于角色的安全文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!