开发者

How could I get the value of the authorized users from the location path in web.config?

开发者 https://www.devze.com 2023-01-18 16:37 出处:网络
This is part of my web.config <location path=\"Secure\"> <system.web> <authorization> <allow users=\"SecureUsers\" />

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")
        {

        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消