Access authorization information in web.config

I am writing a special role provider and I need programmatic access to the authorization information stored in the web.config file. Some sections of the site are available only for certain roles. I would like to know which roles can access a page and / or which page access a specific role.

I can't seem to figure this out.

+3
source share
1 answer

You can access any stored information, such as ConnectionStrings, AppSettings, and other specific values ​​in web.config by the WebConfigurationManager class in the System.Web.Security namespace.

Let's say that you defined the authorization section and section as:

<system.web>
<authorization>
  <allow roles="admin,moderator" />
  <deny users="?" />
</authorization></system.web>

, , , , admin / , (), .

GetSection WebConfigurationManager

AuthorizationSection auth = WebConfigurationManager.GetSection("system.web/authorization") as AuthorizationSection;

AuthorizationSection Rules, .

+8

Source: https://habr.com/ru/post/1714541/


All Articles