How could I get the value of the authorized users from the location path in web.config?
This is part of my web.config
<location path="Secure">
<system.web>
<authorization>
<allow users="SecureUsers" />
</authorization>
</system.web>
</location>
I want to be able to search for path of Secure and find out the user role that is specified.
My input is the path, such as "Secure" and 开发者_运维技巧the value I'm trying to retrieve is "SecureUsers".
I think you want to open the config and cast it as a Configuration object before you can really get what you want. You might also be able to read the config file using LINQ to XML too, but here is how you would do it otherwise.
Configuration config = ConfigurationManager.OpenExeConfiguration(Server.MapPath("~/web.config"));
ConfigurationLocationCollection myLocationCollection = config.Locations;
foreach (ConfigurationLocation myLocation in myLocationCollection)
{
if (myLocation.Path == "Secure")
{
}
}
精彩评论