public void TestDebugFalse() { var path = @"Path to web.config"; var webConfig = new System.IO.FileInfo(path); var virtualDirectoryMapping = new System.Web.Configuration.VirtualDirectoryMapping(webConfig.DirectoryName, true, webConfig.Name); var fileMap = new System.Web.Configuration.WebConfigurationFileMap(); fileMap.VirtualDirectories.Add("/", virtualDirectoryMapping); var configuration = System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/"); var compilation = configuration.GetSection("system.web/compilation") as System.Web.Configuration.CompilationSection; if (compilation != null) { Assert.AreEqual(false, compilation.Debug); } }
/// <summary> /// Auto-wires the application variables and the log file path in the web.config file. /// </summary> /// <param name="configPath">The config file path.</param> /// <param name="variables">The variables.</param> /// <param name="logFilePath">The log file path.</param> /// <param name="errorLogFilePath">The error log file path.</param> private void SetApplicationVariables(string configPath, ApplicationVariable[] variables, string logFilePath, string errorLogFilePath) { this.startupLogger.Info(Strings.SettingUpApplicationVariables); var configFile = new FileInfo(configPath); var vdm = new System.Web.Configuration.VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); var wcfm = new System.Web.Configuration.WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); System.Configuration.Configuration webConfig = System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); bool hasUhuruLogFile = false; bool hasUhuruErrorLogFile = false; foreach (ApplicationVariable var in variables) { if (var.Name == "UHURU_LOG_FILE") { hasUhuruLogFile = true; } if (var.Name == "UHURU_ERROR_LOG_FILE") { hasUhuruErrorLogFile = true; } if (webConfig.AppSettings.Settings[var.Name] == null) { webConfig.AppSettings.Settings.Add(var.Name, var.Value); } else { webConfig.AppSettings.Settings[var.Name].Value = var.Value; } } if (!hasUhuruLogFile) { if (webConfig.AppSettings.Settings["UHURU_LOG_FILE"] == null) { webConfig.AppSettings.Settings.Add("UHURU_LOG_FILE", logFilePath); } else { webConfig.AppSettings.Settings["UHURU_LOG_FILE"].Value = logFilePath; } } if (!hasUhuruErrorLogFile) { if (webConfig.AppSettings.Settings["UHURU_ERROR_LOG_FILE"] == null) { webConfig.AppSettings.Settings.Add("UHURU_ERROR_LOG_FILE", errorLogFilePath); } else { webConfig.AppSettings.Settings["UHURU_ERROR_LOG_FILE"].Value = errorLogFilePath; } } this.startupLogger.Info(Strings.DoneSettingUpApplication); webConfig.Save(); }