public void SetEngines(HeliconZooEngine[] userEngines) { // Write to applicationHost.config using (var srvman = new ServerManager()) { Configuration appConfig = srvman.GetApplicationHostConfiguration(); ConfigurationSection heliconZooServer = appConfig.GetSection("system.webServer/heliconZooServer"); ConfigurationElement engines = heliconZooServer.GetChildElement("userEngines"); ConfigurationElementCollection enginesCollection = engines.GetCollection(); enginesCollection.Clear(); ConfigurationElement switchboard = heliconZooServer.GetChildElement("switchboard"); ConfigurationElementCollection switchboardCollection = switchboard.GetCollection(); switchboardCollection.Clear(); foreach (HeliconZooEngine item in userEngines) { if (item.isUserEngine) { ConfigurationElement engine = enginesCollection.CreateElement(); ConvertHeliconZooEngineToElement(item, engine); enginesCollection.Add(engine); } } srvman.CommitChanges(); } }
} // SetWebSiteUploadLimitation private int GetWebSiteUploadLimitation(Microsoft.Web.Administration.Configuration oConfig, string sControllerAction) { int nResult = 0; try { ConfigurationSection requestFilteringSection = string.IsNullOrWhiteSpace(sControllerAction) ? oConfig.GetSection(SectionPath) : oConfig.GetSection(SectionPath, sControllerAction); ConfigurationElement requestLimitsElement = requestFilteringSection.GetChildElement(ElementName); ConfigurationAttribute oAttr = requestLimitsElement.GetAttribute(AttributeName); if (oAttr != null) { int macl; if (int.TryParse(oAttr.Value.ToString(), out macl)) { nResult = macl; } else { m_oLog.Warn("Failed to parse upload limit for action '{0}'.", sControllerAction); } } // if m_oLog.Debug("Current upload limit for action '{1}' is {0} bytes.", nResult, sControllerAction); } catch (Exception e) { m_oLog.Warn(e, "Failed to load upload limit for action '{0}'.", sControllerAction); } // try return(nResult); } // GetWebSiteUploadLimitation
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Default Web Site"); windowsAuthenticationSection["enabled"] = true; ConfigurationElement extendedProtectionElement = windowsAuthenticationSection.GetChildElement("extendedProtection"); extendedProtectionElement["tokenChecking"] = @"Allow"; extendedProtectionElement["flags"] = @"None"; ConfigurationElementCollection extendedProtectionCollection = extendedProtectionElement.GetCollection(); ConfigurationElement spnElement = extendedProtectionCollection.CreateElement("spn"); spnElement["name"] = @"HTTP/www.contoso.com"; extendedProtectionCollection.Add(spnElement); ConfigurationElement spnElement1 = extendedProtectionCollection.CreateElement("spn"); spnElement1["name"] = @"HTTP/contoso.com"; extendedProtectionCollection.Add(spnElement1); serverManager.CommitChanges(); } }
public void SetWebCosoleEnabled(bool enabled) { using (var srvman = new ServerManager()) { Configuration appConfig = srvman.GetApplicationHostConfiguration(); ConfigurationSection heliconZooServer = appConfig.GetSection("system.webServer/heliconZooServer"); ConfigurationElement switchboard = heliconZooServer.GetChildElement("switchboard"); ConfigurationElementCollection switchboardCollection = switchboard.GetCollection(); bool found = false; foreach (ConfigurationElement switchboardElement in switchboardCollection) { if ((string)switchboardElement.GetAttributeValue("name") == "console") { SetSwitchBoardValue(switchboardElement, enabled); found = true; break; } } if (!found) { ConfigurationElement element = switchboardCollection.CreateElement(); element.SetAttributeValue("name", "console"); SetSwitchBoardValue(element, enabled); switchboardCollection.Add(element); } srvman.CommitChanges(); } }
private static void DisplaySections() { // 获取IIS配置文件:applicationHost.config using (ServerManager manager = new ServerManager()) { Configuration configuration = manager.GetAdministrationConfiguration(); Configuration config = manager.GetApplicationHostConfiguration(); ConfigurationSection log = config.GetSection("system.applicationHost/log"); ConfigurationElement logFile = log.GetChildElement("centralW3CLogFile"); string logPath = logFile.GetAttributeValue("directory").ToString(); ConfigurationSection configPaths = config.GetSection("configPaths"); foreach (ConfigurationElement configPath in configPaths.GetCollection()) { string path = (string)configPath["path"]; string locationPath = (string)configPath["locationPath"]; Console.WriteLine(); Console.WriteLine("Config Path:" + path); if (!String.IsNullOrEmpty(locationPath)) { Console.WriteLine("<locationPath path=" + locationPath + "'>"); } foreach (ConfigurationElement section in configPath.GetCollection()) { Console.WriteLine(" " + section["name"]); } } } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection requestFilteringSection = config.GetSection("system.ftpServer/security/requestFiltering", "Default Web Site"); ConfigurationElement fileExtensionsElement = requestFilteringSection.GetChildElement("fileExtensions"); ConfigurationElementCollection fileExtensionsCollection = fileExtensionsElement.GetCollection(); ConfigurationElement addElement = fileExtensionsCollection.CreateElement("add"); addElement["fileExtension"] = @".exe"; addElement["allowed"] = false; fileExtensionsCollection.Add(addElement); ConfigurationElement addElement1 = fileExtensionsCollection.CreateElement("add"); addElement1["fileExtension"] = @".com"; addElement1["allowed"] = false; fileExtensionsCollection.Add(addElement1); ConfigurationElement addElement2 = fileExtensionsCollection.CreateElement("add"); addElement2["fileExtension"] = @".cmd"; addElement2["allowed"] = false; fileExtensionsCollection.Add(addElement2); ConfigurationElement addElement3 = fileExtensionsCollection.CreateElement("add"); addElement3["fileExtension"] = @".bat"; addElement3["allowed"] = false; fileExtensionsCollection.Add(addElement3); serverManager.CommitChanges(); } }
private static void RegisterPhpDefaultDocument(ConfigurationSection defaultDocument) { ConfigurationElement defaultFiles = defaultDocument.GetChildElement("files"); ConfigurationElementCollection filesCollection = defaultFiles.GetCollection(); // search index.php in default documents bool indexPhpPresent = false; foreach (ConfigurationElement configurationElement in filesCollection) { string value = configurationElement.GetAttributeValue("value") as string; if (!string.IsNullOrEmpty(value)) { if (string.Equals(value, "index.php", StringComparison.OrdinalIgnoreCase)) { indexPhpPresent = true; break; } } } if (!indexPhpPresent) { // add index.php ConfigurationElement indexPhp = filesCollection.CreateElement(); indexPhp.SetAttributeValue("value", "index.php"); filesCollection.AddAt(0, indexPhp); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults"); ConfigurationElement limitsElement = siteDefaultsElement.GetChildElement("limits"); limitsElement["connectionTimeout"] = TimeSpan.Parse("00:02:00"); ConfigurationElement logFileElement = siteDefaultsElement.GetChildElement("logFile"); logFileElement["logFormat"] = @"W3C"; logFileElement["directory"] = @"%SystemDrive%\inetpub\logs\LogFiles"; logFileElement["enabled"] = true; ConfigurationElement traceFailedRequestsLoggingElement = siteDefaultsElement.GetChildElement("traceFailedRequestsLogging"); traceFailedRequestsLoggingElement["enabled"] = true; traceFailedRequestsLoggingElement["directory"] = @"%SystemDrive%\inetpub\logs\FailedReqLogFiles"; traceFailedRequestsLoggingElement["maxLogFiles"] = 20; ConfigurationElementCollection bindingsCollection = siteDefaultsElement.GetCollection("bindings"); ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding"); bindingElement["protocol"] = @"http"; bindingElement["bindingInformation"] = @"127.0.0.1:8080:"; bindingsCollection.Add(bindingElement); ConfigurationElement ftpServerElement = siteDefaultsElement.GetChildElement("ftpServer"); ftpServerElement["serverAutoStart"] = true; serverManager.CommitChanges(); } }
public bool IsWebCosoleEnabled() { bool isEnginesEnabled = true; using (var srvman = new ServerManager()) { Configuration appConfig = srvman.GetApplicationHostConfiguration(); ConfigurationSection heliconZooServer = appConfig.GetSection("system.webServer/heliconZooServer"); //switchboard ConfigurationElement switchboard = heliconZooServer.GetChildElement("switchboard"); ConfigurationElementCollection switchboardCollection = switchboard.GetCollection(); foreach (ConfigurationElement switchboardElement in switchboardCollection) { if ((string)switchboardElement.GetAttributeValue("name") == "console") { isEnginesEnabled = GetSwitchBoardValue(switchboardElement); break; } } } return(isEnginesEnabled); }
public static void AddDefaultDocument(string siteName, string defaultDocName) { using (ServerManager mgr = new ServerManager()) { Configuration cfg = mgr.GetWebConfiguration(siteName); ConfigurationSection defaultDocumentSection = cfg.GetSection("system.webServer/defaultDocument"); ConfigurationElement filesElement = defaultDocumentSection.GetChildElement("files"); ConfigurationElementCollection filesCollection = filesElement.GetCollection(); foreach (ConfigurationElement elt in filesCollection) { if (elt.Attributes["value"].Value.ToString() == defaultDocName) { return; } } try { ConfigurationElement docElement = filesCollection.CreateElement(); docElement.SetAttributeValue("value", defaultDocName); filesCollection.Add(docElement); } catch (Exception) { } //this will fail if existing mgr.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElement applicationDefaultsElement = sitesSection.GetChildElement("applicationDefaults"); applicationDefaultsElement["applicationPool"] = @"DefaultAppPool"; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElement virtualDirectoryDefaultsElement = sitesSection.GetChildElement("virtualDirectoryDefaults"); virtualDirectoryDefaultsElement["logonMethod"] = @"Network"; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection serverRuntimeSection = config.GetSection("system.ftpServer/serverRuntime"); ConfigurationElement hostNameSupportElement = serverRuntimeSection.GetChildElement("hostNameSupport"); hostNameSupportElement["useDomainNameAsHostName"] = true; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetWebConfiguration("Default Web Site", "MyVirtualDir"); ConfigurationSection staticContentSection = config.GetSection("system.webServer/staticContent"); ConfigurationElement clientCacheElement = staticContentSection.GetChildElement("clientCache"); clientCacheElement["cacheControlMode"] = @"DisableCache"; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection dynamicIpSecuritySection = config.GetSection("system.webServer/security/dynamicIpSecurity", "Default Web Site"); dynamicIpSecuritySection["denyAction"] = @"Forbidden"; dynamicIpSecuritySection["enableProxyMode"] = true; dynamicIpSecuritySection["enableLoggingOnlyMode"] = true; ConfigurationElement denyByConcurrentRequestsElement = dynamicIpSecuritySection.GetChildElement("denyByConcurrentRequests"); denyByConcurrentRequestsElement["enabled"] = true; denyByConcurrentRequestsElement["maxConcurrentRequests"] = 10; ConfigurationElement denyByRequestRateElement = dynamicIpSecuritySection.GetChildElement("denyByRequestRate"); denyByRequestRateElement["enabled"] = true; denyByRequestRateElement["maxRequests"] = 10; denyByRequestRateElement["requestIntervalInMilliseconds"] = 10; serverManager.CommitChanges(); } }
public void ConfigureProxy() { // For this local CDN to work we need IIS-ARR installed and configured at the IIS level, otherwise // IIS gets stuck with this config (+ it won't work) try { // Ensure that proxy is enabled and available at the IIS level. // This needs the IIS Application Request Routing extension. using (ServerManager manager = new ServerManager()) { bool configChanged = false; var config = manager.GetApplicationHostConfiguration(); ConfigurationSection proxySection = config.GetSection("system.webServer/proxy"); // Disable reverseRewriteHostInResponseHeaders if (!bool.TryParse(proxySection["reverseRewriteHostInResponseHeaders"]?.ToString(), out var proxyReverseRewrite) || proxyReverseRewrite == true) { proxySection["reverseRewriteHostInResponseHeaders"] = false; configChanged = true; } // Enable proxy functionality if (!bool.TryParse(proxySection["enabled"]?.ToString(), out var proxyEnabled) || proxyEnabled == false) { proxySection["enabled"] = true; configChanged = true; } // Disable disk cache ConfigurationElement cacheElement = proxySection.GetChildElement("cache"); if (!bool.TryParse(cacheElement["enabled"]?.ToString(), out var cacheEnabled) || cacheEnabled == true) { cacheElement["enabled"] = false; configChanged = true; } if (configChanged) { this.Logger.LogWarning(false, "Your IIS-ARR settings have been updated to work with Chef CDN: [proxy.enabled=true] && [proxy.cache.enabled=false]"); UtilsIis.CommitChanges(manager); } } } catch (Exception e) { throw new Exception("Could not configure server-wide proxy settings for CDN related functionality. Make sure that the chocolatey iis-arr package is installed.", e); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection aspSection = config.GetSection("system.webServer/asp", "Default Web Site"); ConfigurationElement comPlusElement = aspSection.GetChildElement("comPlus"); comPlusElement["trackThreadingModel"] = true; comPlusElement["executeInMta"] = true; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection logSection = config.GetSection("system.applicationHost/log"); logSection["centralLogFileMode"] = @"CentralBinary"; ConfigurationElement centralBinaryLogFileElement = logSection.GetChildElement("centralBinaryLogFile"); centralBinaryLogFileElement["period"] = @"Daily"; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection cachingSection = config.GetSection("system.ftpServer/caching"); ConfigurationElement credentialsCacheElement = cachingSection.GetChildElement("credentialsCache"); credentialsCacheElement["enabled"] = true; credentialsCacheElement["flushInterval"] = 300; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection requestFilteringSection = config.GetSection("system.ftpServer/security/requestFiltering", "Default Web Site"); ConfigurationElement requestLimitsElement = requestFilteringSection.GetChildElement("requestLimits"); requestLimitsElement["maxAllowedContentLength"] = 1000000; requestLimitsElement["maxUrl"] = 1024; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetWebConfiguration("Default Web Site"); ConfigurationSection staticContentSection = config.GetSection("system.webServer/staticContent"); ConfigurationElement clientCacheElement = staticContentSection.GetChildElement("clientCache"); clientCacheElement["cacheControlMode"] = @"UseExpires"; clientCacheElement["httpExpires"] = @"Tue, 19 Jan 2038 03:14:07 GMT"; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults"); ConfigurationElement limitsElement = siteDefaultsElement.GetChildElement("limits"); limitsElement["connectionTimeout"] = TimeSpan.Parse("00:03:00"); serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection authoringSection = config.GetSection("system.webServer/webdav/authoring", "Default Web Site"); ConfigurationElement fileSystemElement = authoringSection.GetChildElement("fileSystem"); fileSystemElement["allowHiddenFiles"] = true; fileSystemElement["hideChildVirtualDirectories"] = true; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection authoringSection = config.GetSection("system.webServer/webdav/authoring", "Default Web Site"); ConfigurationElement locksElement = authoringSection.GetChildElement("locks"); locksElement["enabled"] = true; locksElement["lockStore"] = @"webdav_simple_lock"; locksElement["requireLockForWriting"] = false; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults"); ConfigurationElement ftpServerElement = siteDefaultsElement.GetChildElement("ftpServer"); ConfigurationElement fileHandlingElement = ftpServerElement.GetChildElement("fileHandling"); fileHandlingElement["keepPartialUploads"] = false; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults"); ConfigurationElement ftpServerElement = siteDefaultsElement.GetChildElement("ftpServer"); ConfigurationElement directoryBrowseElement = ftpServerElement.GetChildElement("directoryBrowse"); directoryBrowseElement["showFlags"] = @"StyleUnix, DisplayAvailableBytes"; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection aspSection = config.GetSection("system.webServer/asp"); ConfigurationElement limitsElement = aspSection.GetChildElement("limits"); limitsElement["scriptTimeout"] = TimeSpan.Parse("00:02:00"); limitsElement["queueConnectionTestTime"] = TimeSpan.Parse("00:00:05"); limitsElement["requestQueueMax"] = 1000; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools"); ConfigurationElement applicationPoolDefaultsElement = applicationPoolsSection.GetChildElement("applicationPoolDefaults"); applicationPoolDefaultsElement["autoStart"] = true; applicationPoolDefaultsElement["managedRuntimeVersion"] = @"v2.0"; applicationPoolDefaultsElement["managedPipelineMode"] = @"Integrated"; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults"); ConfigurationElement ftpServerElement = siteDefaultsElement.GetChildElement("ftpServer"); ConfigurationElement securityElement = ftpServerElement.GetChildElement("security"); ConfigurationElement customAuthorizationElement = securityElement.GetChildElement("customAuthorization"); ConfigurationElement providerElement = customAuthorizationElement.GetChildElement("provider"); providerElement["name"] = @"MyCustomProvider"; providerElement["enabled"] = true; serverManager.CommitChanges(); } }
private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection logSection = config.GetSection("system.ftpServer/log"); logSection["centralLogFileMode"] = @"Central"; ConfigurationElement centralLogFileElement = logSection.GetChildElement("centralLogFile"); centralLogFileElement["enabled"] = true; serverManager.CommitChanges(); } }