Я создал для этого функцию, которая будет использовать область web.config, если пользователь использует эту область, в противном случае будет использоваться корневой файл web.config:
public static T GetWebConfigSection<T>(Controller controller, string sectionName) where T : class
{
T returnValue = null;
String area = null;
var routeArea = controller.RouteData.DataTokens["area"];
if(routeArea != null)
area = routeArea.ToString();
System.Configuration.Configuration configFile = null;
if (area == null)
{
// User is not in an area so must be at the root of the site so open web.config
configFile = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
}
else
{
// User is in an Area, so open the web.config file in the Area/views folder (e.g. root level for the area)
configFile = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Areas/" + area + "/Views");
}
if (configFile != null)
returnValue = configFile.GetSection(sectionName) as T;
return returnValue;
}
И затем вызов:
ForestSettings forestSettings = ConfigFunctions.GetWebConfigSection<ForestSettings>(controller, "myCompanyConfiguration/forestSettings");