开发者

Retriving a setting in a Web.Config <configSections>

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜