.net 访问web.config中的授权信息

.net 访问web.config中的授权信息,.net,authorization,roleprovider,.net,Authorization,Roleprovider,我正在编写一个自定义角色提供程序,需要通过编程访问存储在web.config中的授权信息。 网站的某些部分只能由某些角色访问。我想了解哪些角色可以访问某个页面和/或某个角色可以访问哪个页面 我似乎无法理解这一点 您可以通过System.web.Security命名空间中的WebConfiguration Manager类访问存储在web.config中的任何信息,例如ConnectionString、AppSettings和其他定义的值 假设您已将“授权”部分定义为: <system.we

我正在编写一个自定义角色提供程序,需要通过编程访问存储在web.config中的授权信息。 网站的某些部分只能由某些角色访问。我想了解哪些角色可以访问某个页面和/或某个角色可以访问哪个页面


我似乎无法理解这一点

您可以通过System.web.Security命名空间中的WebConfiguration Manager类访问存储在web.config中的任何信息,例如ConnectionString、AppSettings和其他定义的值

假设您已将“授权”部分定义为:

<system.web>
<authorization>
  <allow roles="admin,moderator" />
  <deny users="?" />
</authorization></system.web>
AuthorizationSection类将为您提供
Rules
collection,这正是您要查找的内容。

我在
AuthenticationSection
对象上找不到任何
Rules
集合?AuthorizationSection具有规则集合。我把班名拼错了。这不是AuthenticationSection,而是AuthorizationSection,我编辑我的帖子是为了验证你提到的错误,谢谢你注意到这一点。
AuthorizationSection auth = WebConfigurationManager.GetSection("system.web/authorization") as AuthorizationSection;