Accessing appSettings from multiple Web.config files

前端 未结 2 423
猫巷女王i
猫巷女王i 2021-01-12 10:17

I am designing an ASP.NET MVC4 Web App project. In the root of my project, I have the customary default Web.config file with my corresponding elements. In parti

2条回答
  •  再見小時候
    2021-01-12 10:20

    Figured it out! To use a different config file, incorporate WebConfigurationmanager. So, to access the appSettings of ./Areas/PackageName/Web.config, simply use:

    var config = WebConfigurationManager.OpenWebConfiguration("~/Areas/PackageName");
    string dirE = config.AppSettings.Settings["dirEnabled"].Value;
    

提交回复
热议问题