private void GetConfig()
{
_log.Debug("Init: reading configuration from " + _appRoot + "/web.config");
// Assume web.config is in app root. This may be fragile; I don't know enough about
// all the configuration permutations of IIS. Possible to not have a web.config in an app root?
System.Configuration.Configuration rootWebConfig1 =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(_appRoot + "/Web.config");
// Tried to use app settings, get nullObject excetption when try to iterate through config
//AppSettingsSection appSettings =
// System.Web.Configuration.WebConfigurationManager.GetWebApplicationSection("appSettings")
// as AppSettingsSection;
// foreach (string key in appSettings.Settings.AllKeys)
// {
// _log.Debug("appSettings: " + key + ": " + appSettings.Settings[key]);
// }
if (rootWebConfig1.AppSettings.Settings.Count > 0)
{
System.Configuration.KeyValueConfigurationElement canonicalSettingConfig =
rootWebConfig1.AppSettings.Settings["UseCanonicalName"];
System.Configuration.KeyValueConfigurationElement serverNameConfig =
rootWebConfig1.AppSettings.Settings["ServerName"];
if (serverNameConfig.Value != null
&& canonicalSettingConfig.Value != null
&& string.Equals(canonicalSettingConfig.Value, "On", StringComparison.CurrentCultureIgnoreCase))
{
_useCanonicalName = true;
_canonicalServerName = serverNameConfig.Value;
_log.Debug("Config found, server name is " + _canonicalServerName);
}
else
{
_log.Warn("No valid config found for UseCanonicalName");
}
}
else
{
_log.Warn("Empty or non-existent web.config: rootWebConfig1.AppSettings.Settings.Count <= 0");
}
}