コード例 #1
0
        internal static bool ConfigureApplication(ServerManager serverManager, string webSiteName, string applicationPoolName, string virtualPath, string physicalPath, out bool recycleAppPool)
        {
            bool flag = true;

            recycleAppPool = false;
            Configuration                  applicationHostConfiguration = serverManager.GetApplicationHostConfiguration();
            ConfigurationSection           section               = applicationHostConfiguration.GetSection("system.applicationHost/sites");
            ConfigurationElementCollection collection            = section.GetCollection();
            ConfigurationElement           configurationElement  = IISConfigurationUtilities.FindElement(collection, "site", "name", webSiteName);
            ConfigurationElementCollection collection2           = configurationElement.GetCollection();
            ConfigurationElement           configurationElement2 = IISConfigurationUtilities.FindElement(collection2, "application", "path", virtualPath);

            if (configurationElement2 == null)
            {
                configurationElement2         = collection2.CreateElement("application");
                configurationElement2["path"] = virtualPath;
                collection2.Add(configurationElement2);
                flag = true;
            }
            recycleAppPool |= IISConfigurationUtilities.UpdateElementAttribute(configurationElement2, "applicationPool", applicationPoolName);
            flag           |= recycleAppPool;
            ConfigurationElementCollection collection3           = configurationElement2.GetCollection();
            ConfigurationElement           configurationElement3 = IISConfigurationUtilities.FindElement(collection3, "virtualDirectory", "path", "/");

            if (configurationElement3 == null)
            {
                configurationElement3         = collection3.CreateElement("virtualDirectory");
                configurationElement3["path"] = "/";
                collection3.Add(configurationElement3);
                flag = true;
            }
            return(flag | IISConfigurationUtilities.UpdateElementAttribute(configurationElement3, "physicalPath", physicalPath));
        }
コード例 #2
0
        internal static bool CreateOrUpdateApplicationPool(ServerManager serverManager, string appPoolName, string clrConfigFilePath, out bool isAppPoolNew)
        {
            bool flag = false;

            isAppPoolNew = false;
            ApplicationPoolCollection      applicationPools = serverManager.ApplicationPools;
            ConfigurationElementCollection collection       = applicationPools.GetCollection();

            if (IISConfigurationUtilities.FindElement(collection, "add", "name", appPoolName) == null)
            {
                flag         = true;
                isAppPoolNew = true;
                applicationPools.Add(appPoolName);
            }
            ApplicationPool applicationPool = applicationPools[appPoolName];

            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "autostart", true);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "managedPipelineMode", "Integrated");
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "managedRuntimeVersion", "v4.0");
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "queueLength", 65535);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.Failure, "rapidFailProtection", false);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "identityType", "LocalSystem");
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "loadUserProfile", true);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "idleTimeout", TimeSpan.FromSeconds(0.0));
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "pingingEnabled", false);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.ProcessModel, "shutdownTimeLimit", TimeSpan.FromSeconds(5.0));
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.Recycling, "disallowOverlappingRotation", true);
            flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool.Recycling.PeriodicRestart, "time", TimeSpan.FromSeconds(0.0));
            if (!string.IsNullOrEmpty(clrConfigFilePath))
            {
                flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "CLRConfigFile", clrConfigFilePath);
                flag |= IISConfigurationUtilities.UpdateElementAttribute(applicationPool, "managedRuntimeLoader", string.Empty);
            }
            return(flag);
        }