Reading web.configuration values in asp.net application
In my asp.net application I want to read authorization 开发者_开发技巧section of web.config and modify that. For that I am using the below code but I am not getting the values. So have a look at it and let me know if there is any way to read and update authorization section values AuthorizationSection section; my section is like the following
<authorization>
<deny users="?"/>
</authorization>
And this is the code:
configuration = WebConfigurationManager.OpenWebConfiguration("~");
section = (AuthorizationSection)configuration.GetSection("system.web/authorization");
SectionInformation sc= section.SectionInformation;
Thanks, Hima.
Try this:
AuthorizationSection section = (AuthorizationSection)ConfigurationManager
.GetSection("system.web/authorization");
Add reference to System.Configuration.dll
Update:
Try this:
AuthorizationSection section = (AuthorizationSection)ConfigurationManager
.GetSection("system.web/authorization");
foreach (AuthorizationRule rule in section.Rules)
{
//rule.Users <- StringCollection
//rule.Action;
}
精彩评论