当前位置: 首页>>代码示例>>C#>>正文


C# ServerManager.GetApplicationHostConfiguration方法代码示例

本文整理汇总了C#中Microsoft.Web.Administration.ServerManager.GetApplicationHostConfiguration方法的典型用法代码示例。如果您正苦于以下问题:C# ServerManager.GetApplicationHostConfiguration方法的具体用法?C# ServerManager.GetApplicationHostConfiguration怎么用?C# ServerManager.GetApplicationHostConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Web.Administration.ServerManager的用法示例。


在下文中一共展示了ServerManager.GetApplicationHostConfiguration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Install

        public static void Install(UdpInstallerOptions options)
        {
            if (options.ListenerAdapterChecked)
            {
                WebAdmin.ServerManager sm = new WebAdmin.ServerManager();
                WebAdmin.Configuration wasConfiguration = sm.GetApplicationHostConfiguration();
                WebAdmin.ConfigurationSection section = wasConfiguration.GetSection(ListenerAdapterPath);
                WebAdmin.ConfigurationElementCollection listenerAdaptersCollection = section.GetCollection();
                WebAdmin.ConfigurationElement element = listenerAdaptersCollection.CreateElement();
                element.GetAttribute("name").Value = UdpConstants.Scheme;
                element.GetAttribute("identity").Value = WindowsIdentity.GetCurrent().User.Value;
                listenerAdaptersCollection.Add(element);
                sm.CommitChanges();
                wasConfiguration = null;
                sm = null;
            }

            if (options.ProtocolHandlerChecked)
            {
                Configuration rootWebConfig = GetRootWebConfiguration();
                ProtocolsSection section = (ProtocolsSection)rootWebConfig.GetSection(ProtocolsPath);
                ProtocolElement element = new ProtocolElement(UdpConstants.Scheme);
                
                element.ProcessHandlerType = typeof(UdpProcessProtocolHandler).AssemblyQualifiedName;
                element.AppDomainHandlerType = typeof(UdpAppDomainProtocolHandler).AssemblyQualifiedName;
                element.Validate = false;

                section.Protocols.Add(element);
                rootWebConfig.Save();
            }
        }
开发者ID:ssickles,项目名称:archive,代码行数:31,代码来源:UdpInstaller.cs

示例2: OnStart

        public override bool OnStart()
        {
            try
            {
                Trace.Listeners.Add(new DiagnosticMonitorTraceListener());
                Trace.TraceInformation("Starting Gateway");

                // Enable IIS Reverse Proxy
                using (ServerManager server = new ServerManager())
                {
                    var proxySection = server.GetApplicationHostConfiguration().GetSection("system.webServer/proxy");
                    proxySection.SetAttributeValue("enabled", true);
                    server.CommitChanges();
                    Trace.TraceInformation("Enabled Reverse Proxy");

                    // Patch web.config rewrite rules
                    string serviceStem = RoleEnvironment.GetConfigurationSettingValue("Gateway.ServiceStem");
                    if (!String.Equals(serviceStem, "nuget.org", StringComparison.OrdinalIgnoreCase))
                    {
                        RewriteStem(server, serviceStem);
                    }
                    server.CommitChanges();
                }

                return base.OnStart();
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error starting gateway: {0}", ex.ToString());
                throw;
            }
        }
开发者ID:NuGet,项目名称:NuGet.Services.Gateway,代码行数:32,代码来源:WebRole.cs

示例3: CreateReWriteRule

        private static void CreateReWriteRule(string serverFarm)
        {
            using (var serverManager = new ServerManager())
            {
                var config = serverManager.GetApplicationHostConfiguration();
                var globalRulesSection = config.GetSection("system.webServer/rewrite/globalRules");
                var globalRulesCollection = globalRulesSection.GetCollection();

                var ruleElement = globalRulesCollection.CreateElement("rule");
                ruleElement["name"] = serverFarm;
                ruleElement["patternSyntax"] = @"Wildcard";
                ruleElement["stopProcessing"] = true;

                var matchElement = ruleElement.GetChildElement("match");
                matchElement["url"] = @"*";
                matchElement["ignoreCase"] = false;

                var actionElement = ruleElement.GetChildElement("action");
                actionElement["type"] = @"Rewrite";
                actionElement["url"] = string.Concat(@"http://", serverFarm, @"/{R:0}");
                globalRulesCollection.Add(ruleElement);

                serverManager.CommitChanges();
            }
        }
开发者ID:azure-contrib,项目名称:AzureStickySessions,代码行数:25,代码来源:IISconfiguration.cs

示例4: AddServers

        public static void AddServers(string farmName, IPEndPoint[] endpoints)
        {
            using (var serverManager = new ServerManager())
            {
                var config = serverManager.GetApplicationHostConfiguration();
                var webFarmsSection = config.GetSection("webFarms");
                var webFarmsCollection = webFarmsSection.GetCollection();
                var webFarmElement = FindElement(webFarmsCollection, "webFarm", "name", farmName);
                if (webFarmElement == null) throw new InvalidOperationException("Element not found!");

                var webFarmCollection = webFarmElement.GetCollection();
                foreach (var endpoint in endpoints)
                {
                    var server = FindElement(webFarmCollection, "server", "address", endpoint.Address.ToString());
                    if (null != server)
                    {
                        // server already exists
                        continue;
                    }

                    var serverElement = webFarmCollection.CreateElement("server");
                    serverElement["address"] = endpoint.Address.ToString();

                    var applicationRequestRoutingElement = serverElement.GetChildElement("applicationRequestRouting");
                    applicationRequestRoutingElement["httpPort"] = endpoint.Port;
                    webFarmCollection.Add(serverElement);
                }
                serverManager.CommitChanges();
            }
        }
开发者ID:azure-contrib,项目名称:AzureStickySessions,代码行数:30,代码来源:IISconfiguration.cs

示例5: GetOrCreateFarm

        public static ConfigurationElement GetOrCreateFarm(string farmName)
        {
            using (var serverManager = new ServerManager())
            {
                var config = serverManager.GetApplicationHostConfiguration();
                var webFarmsSection = config.GetSection("webFarms");
                var webFarmsCollection = webFarmsSection.GetCollection();

                var el = FindElement(webFarmsCollection, "webFarm", "name", farmName);
                if (null != el)
                {
                    return el;
                }

                var webFarmElement = webFarmsCollection.CreateElement("webFarm");
                webFarmElement["name"] = farmName;
                webFarmsCollection.Add(webFarmElement);

                var applicationRequestRoutingElement = webFarmElement.GetChildElement("applicationRequestRouting");

                var affinityElement = applicationRequestRoutingElement.GetChildElement("affinity");
                affinityElement["useCookie"] = true;

                serverManager.CommitChanges();

                CreateReWriteRule(farmName);

                return webFarmElement;
            }
        }
开发者ID:azure-contrib,项目名称:AzureStickySessions,代码行数:30,代码来源:IISconfiguration.cs

示例6: Initialize

        public void Initialize()
        {
            if (_configurationProvider.IsEmulated())
            {
                return;
            }

            // Instantiate the IIS ServerManager
            using (var serverManager = new ServerManager())
            {
                Microsoft.Web.Administration.Configuration applicationConfig = serverManager.GetApplicationHostConfiguration();
                ConfigurationSection httpLoggingSection = applicationConfig.GetSection("system.webServer/httpLogging");

                httpLoggingSection["selectiveLogging"] = @"LogAll";
                httpLoggingSection["dontLog"] = false;

                ConfigurationSection sitesSection = applicationConfig.GetSection("system.applicationHost/sites");
                ConfigurationElement siteElement = sitesSection.GetCollection().Single();
                ConfigurationElement logFileElement = siteElement.GetChildElement("logFile");

                logFileElement["logFormat"] = "W3C";
                logFileElement["period"] = "Hourly";
                logFileElement["enabled"] = true;
                logFileElement["logExtFileFlags"] =
                    "BytesRecv,BytesSent,ClientIP,ComputerName,Cookie,Date,Host,HttpStatus,HttpSubStatus,Method,ProtocolVersion,Referer,ServerIP,ServerPort,SiteName,Time,TimeTaken,UriQuery,UriStem,UserAgent,UserName,Win32Status";

                serverManager.CommitChanges();
            }
        }
开发者ID:GusLab,项目名称:video-portal,代码行数:29,代码来源:IisLoggingInitializer.cs

示例7: CreateWebDavRule

        public void CreateWebDavRule(string organizationId, string folder, WebDavFolderRule rule)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                Configuration config = serverManager.GetApplicationHostConfiguration();

                ConfigurationSection authoringRulesSection = config.GetSection("system.webServer/webdav/authoringRules", string.Format("{0}/{1}/{2}", _Setting.Domain, organizationId, folder));

                ConfigurationElementCollection authoringRulesCollection = authoringRulesSection.GetCollection();

                ConfigurationElement addElement = authoringRulesCollection.CreateElement("add");

                if (rule.Users.Any())
                {
                    addElement["users"] = string.Join(", ", rule.Users.Select(x => x.ToString()).ToArray());
                }

                if (rule.Roles.Any())
                {
                    addElement["roles"] = string.Join(", ", rule.Roles.Select(x => x.ToString()).ToArray());
                }

                if (rule.Pathes.Any())
                {
                    addElement["path"] = string.Join(", ", rule.Pathes.ToArray());
                }

                addElement["access"] = rule.AccessRights;
                authoringRulesCollection.Add(addElement);

                serverManager.CommitChanges();
            }
        }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:33,代码来源:WebDav.cs

示例8: OnStart

        public override bool OnStart()
        {
            try
            {
                using (var server = new ServerManager())
                {
                    const string site = "Web";

                    var siteName = string.Format("{0}_{1}", RoleEnvironment.CurrentRoleInstance.Id, site);
                    var config = server.GetApplicationHostConfiguration();
                    ConfigureAccessSection(config, siteName);

                    var iisClientCertificateMappingAuthenticationSection = EnableIisClientCertificateMappingAuthentication(config, siteName);
                    ConfigureManyToOneMappings(iisClientCertificateMappingAuthenticationSection);
                    ConfigureOneToOneMappings(iisClientCertificateMappingAuthenticationSection);

                    server.CommitChanges();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                // handle error here
            }

            return base.OnStart();
        }
开发者ID:showlowtech,项目名称:AzureWithCertificatesSample,代码行数:27,代码来源:WebRole.cs

示例9: Initialize

        public void Initialize()
        {
            if (_configurationProvider.IsEmulated())
            {
                return;
            }

            // Instantiate the IIS ServerManager
            using (var serverManager = new ServerManager())
            {
                // Disable idle timeout & set queue length to 5000
                serverManager.ApplicationPoolDefaults.ProcessModel.IdleTimeout = TimeSpan.Zero;
                serverManager.ApplicationPoolDefaults.QueueLength = 5000;

                // Server runtime configuration
                Microsoft.Web.Administration.Configuration applicationConfig = serverManager.GetApplicationHostConfiguration();

                // Server runtime settings
                // http://www.iis.net/configreference/system.webserver/serverruntime
                ConfigurationSection serverRuntimeSection = applicationConfig.GetSection("system.webServer/serverRuntime", "");
                serverRuntimeSection["enabled"] = true;
                serverRuntimeSection["frequentHitThreshold"] = 1;
                serverRuntimeSection["frequentHitTimePeriod"] = TimeSpan.Parse("00:00:10");

                // Compression settings
                // http://www.iis.net/configreference/system.webserver/httpcompression
                ConfigurationSection httpCompressionSection = applicationConfig.GetSection("system.webServer/httpCompression");
                httpCompressionSection["noCompressionForHttp10"] = false;
                httpCompressionSection["noCompressionForProxies"] = false;
                ConfigurationElementCollection dynamicTypesCollection = httpCompressionSection.GetCollection("dynamicTypes");

                ConfigurationElement addElement = dynamicTypesCollection.CreateElement("add");
                addElement["mimeType"] = @"application/json";
                addElement["enabled"] = true;
                try
                {
                    dynamicTypesCollection.Add(addElement);
                }
                catch (COMException)
                {
                    // add json element already exists
                }

                addElement = dynamicTypesCollection.CreateElement("add");
                addElement["mimeType"] = @"application/xml";
                addElement["enabled"] = true;
                try
                {
                    dynamicTypesCollection.Add(addElement);
                }
                catch (COMException)
                {
                    // add xml element already exists
                }

                // Commit the changes
                serverManager.CommitChanges();
            }
        }
开发者ID:GusLab,项目名称:video-portal,代码行数:59,代码来源:AspInitializer.cs

示例10: GetAuthenticationSettings

        public void GetAuthenticationSettings(ServerManager srvman, WebVirtualDirectory virtualDir)
        {
			var config = srvman.GetApplicationHostConfiguration();
			//
			var section = config.GetSection(Constants.BasicAuthenticationSection, virtualDir.FullQualifiedPath);
			//
			virtualDir.EnableBasicAuthentication = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute));
        }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:8,代码来源:BasicAuthModuleService.cs

示例11: GetAuthenticationSettings

        public PropertyBag GetAuthenticationSettings(ServerManager srvman, string siteId)
        {
            PropertyBag bag = new PropertyBag();
			var config = srvman.GetApplicationHostConfiguration();
			//
			var section = config.GetSection(Constants.WindowsAuthenticationSection, siteId);
			//
			bag[AuthenticationGlobals.IsLocked] = section.IsLocked;
			bag[AuthenticationGlobals.Enabled] = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute));
            return bag;
        }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:11,代码来源:WindowsAuthenticationModuleService.cs

示例12: CreateFtpSite

        /// <summary>
        /// Creates an ftp virtual directory on the "fileService" ftp site.
        /// </summary>
        /// <param name="siteName">The name of the new ftp site.</param>
        /// <param name="directory">The target physical path of the virtual directory.</param>
        /// <param name="port">The port.</param>
        public static void CreateFtpSite(string siteName, string directory, int port)
        {
            using (ServerManager serverManager = new ServerManager())
            {
                Configuration config = serverManager.GetApplicationHostConfiguration();

                ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");

                ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();

                ConfigurationElement siteElement = sitesCollection.CreateElement("site");
                siteElement["name"] = siteName;
                siteElement["id"] = port;

                ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings");

                ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
                bindingElement["protocol"] = @"ftp";
                bindingElement["bindingInformation"] = string.Format(CultureInfo.InvariantCulture, @"*:{0}:", port);
                bindingsCollection.Add(bindingElement);

                ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");

                ConfigurationElement securityElement = ftpServerElement.GetChildElement("security");

                ConfigurationElement sslElement = securityElement.GetChildElement("ssl");
                sslElement["controlChannelPolicy"] = "SslAllow";
                sslElement["dataChannelPolicy"] = "SslAllow";

                ConfigurationElement authenticationElement = securityElement.GetChildElement("authentication");

                ConfigurationElement basicAuthenticationElement = authenticationElement.GetChildElement("basicAuthentication");
                basicAuthenticationElement["enabled"] = true;

                ConfigurationElementCollection siteCollection = siteElement.GetCollection();

                ConfigurationElement applicationElement = siteCollection.CreateElement("application");
                applicationElement["path"] = @"/";

                ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();

                ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
                virtualDirectoryElement["path"] = @"/";
                virtualDirectoryElement["physicalPath"] = new DirectoryInfo(directory).FullName;
                applicationCollection.Add(virtualDirectoryElement);
                siteCollection.Add(applicationElement);
                sitesCollection.Add(siteElement);

                serverManager.CommitChanges();
            }

            Uhuru.Utilities.FirewallTools.OpenPort(port, string.Format(CultureInfo.InvariantCulture, "FTP_{0}", siteName));
        }
开发者ID:UhuruSoftware,项目名称:vcap-dotnet,代码行数:59,代码来源:FtpUtilities.cs

示例13: GetClassicAspSettings

		public PropertyBag GetClassicAspSettings(ServerManager srvman, string siteId)
        {
			var config = srvman.GetApplicationHostConfiguration();
			//
			var aspSection = config.GetSection(SectionName, siteId);
			//
			PropertyBag bag = new PropertyBag();
			//
			bag[ClassicAspGlobals.EnableParentPaths] = Convert.ToBoolean(aspSection.GetAttributeValue(EnableParentPathsAttribute));
			//
			return bag;
        }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:12,代码来源:ClassicAspModuleService.cs

示例14: GetSettings

 public PropertyBag GetSettings(ServerManager srvman, string siteId)
 {
     var config = srvman.GetApplicationHostConfiguration();
     //
     var section = config.GetSection(Constants.CompressionSection, siteId);
     //
     PropertyBag bag = new PropertyBag();
     //
     bag[CompressionGlobals.DynamicCompression] = Convert.ToBoolean(section.GetAttributeValue(DynamicCompression));
     bag[CompressionGlobals.StaticCompression] = Convert.ToBoolean(section.GetAttributeValue(StaticCompression));
     //
     return bag;
 }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:13,代码来源:CompressionModuleService.cs

示例15: GetAuthenticationSettings

		public PropertyBag GetAuthenticationSettings(ServerManager srvman, string siteId)
        {
			var config = srvman.GetApplicationHostConfiguration();
			//
			var section = config.GetSection(Constants.AnonymousAuthenticationSection, siteId);
			//
			PropertyBag bag = new PropertyBag();
			//
			bag[AuthenticationGlobals.AnonymousAuthenticationUserName] = Convert.ToString(section.GetAttributeValue(UserNameAttribute));
			bag[AuthenticationGlobals.AnonymousAuthenticationPassword] = Convert.ToString(section.GetAttributeValue(PasswordAttribute));
			bag[AuthenticationGlobals.Enabled] = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute));
			bag[AuthenticationGlobals.IsLocked] = section.IsLocked;
			//
			return bag;
        }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:15,代码来源:AnonymAuthModuleService.cs


注:本文中的Microsoft.Web.Administration.ServerManager.GetApplicationHostConfiguration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。