开发者

Retriving a setting in a Web.Config <configSections>

开发者 https://www.devze.com 2023-04-08 06:23 出处:网络
I have this code in my Web.Config file: <configSections> <section name=\"myWebAppSettings\" type=\"System.Configuration.SingleTagSectionHandler\" />

I have this code in my Web.Config file:

   <configSections>
        <section name="myWebAppSettings" type="System.Configuration.SingleTagSectionHandler" />
    </configSections&开发者_Go百科gt;
    <myWebAppSettings isTestEnvironment="true"/>

I need retrieve my value isTestEviroment from Global.asax

At the moment I use with no sucess:

bool isTestEnvironment = ConfigurationManager.AppSettings.GetValues["isTestEnvironment"];

What I'm doing wrong here? NOTES: I do not assume my Web.Config file is right so please feel free to change it if I did not written correctly. Thanks for your help on this!


ConfigurationManager.AppSettings retrieves values from the AppSettings configuration element, not your custom section.

You need to use:

var section = (HashTable)ConfigurationManager.GetSection("myWebAppSettings");
bool isTest = Boolean.Parse(section["isTestEnvironment"].ToString());
0

精彩评论

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