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


C# ServerManager.CommitChanges方法代码示例

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


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

示例1: 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

示例2: CreateWebSite

        /// <summary>
        /// Create the web site.
        /// </summary>
        /// <param name="appPoolName">Name of the application pool.</param>
        /// <param name="name">The name.</param>
        /// <param name="protocol">The protocol.</param>
        /// <param name="ip">The ip.</param>
        /// <param name="domains">The domains.</param>
        /// <param name="port">The port.</param>
        /// <param name="physicalPath">The physical path.</param>
        public static void CreateWebSite(string appPoolName, string name, string protocol, string ip, string[] domains, string port, string physicalPath)
        {
            var iisManager = new ServerManager();
            var site = GetSite(iisManager, name, false);
            if (site != null)
            {
                site.Stop();
            }

            if (site == null)
            {
                var mainDomain = domains[0];
                string bindingInfo = string.Format(@"{0}:{1}:{2}", ip, port, mainDomain);
                iisManager.Sites.Add(name, "http", bindingInfo, physicalPath);
                iisManager.CommitChanges();
                site = iisManager.Sites.First(s => s.Name == name);
                site.ServerAutoStart = true;
                site.Applications.First().ApplicationPoolName = appPoolName;
            }
            //add bindings
            //
            AddBindings(site, domains.Select(d => string.Format(@"{0}:{1}:{2}", ip, port, d)).ToArray(), protocol);

            //change application pool
            //
            AddApplicationPools(appPoolName, site);

            //save changes
            //
            iisManager.CommitChanges();

            Thread.Sleep(1000);
            site.Start();
        }
开发者ID:FordSoft,项目名称:CMS,代码行数:44,代码来源:IISHelper.cs

示例3: CreateIISWebSite

        public static void CreateIISWebSite(string siteName, string siteAddress, string physicalPath)
        {
            ServerManager iisManager = new ServerManager();
            Site site = iisManager.Sites[siteName];
            if (site != null)
            {
                iisManager.Sites.Remove(iisManager.Sites[siteName]);
                iisManager.CommitChanges();
            }

            iisManager.Sites.Add(siteName, "http", string.Concat("*:80:", siteAddress), physicalPath);
            iisManager.CommitChanges();
            iisManager.Dispose();
        }
开发者ID:rut5949,项目名称:Dnn.Platform,代码行数:14,代码来源:IISManager.cs

示例4: SetAppPoolIdentity

        /// <summary>
        /// This method iterates over the used application pools of the Azure Cloud Services Web role and changes the application pool account from NETWORK to SYSTEM. This is
        /// needed to make to code work with the Microsoft Online Services Sign In Assistant
        /// </summary>
        private void SetAppPoolIdentity()
        {

            Action<string> iis7fix = (appPoolName) =>
            {
                bool committed = false;
                while (!committed)
                {
                    try
                    {
                        using (ServerManager sm = new ServerManager())
                        {
                            var applicationPool = sm.ApplicationPools[appPoolName];
                            applicationPool.ProcessModel.IdentityType = ProcessModelIdentityType.LocalSystem;
                            sm.CommitChanges();
                            committed = true;
                        }
                    }
                    catch (FileLoadException fle)
                    {
                        Trace.TraceError("Trying again because: " + fle.Message);
                    }
                }
            };

            var sitename = RoleEnvironment.CurrentRoleInstance.Id + "_Web";
            var appPoolNames = new ServerManager().Sites[sitename].Applications.Select(app => app.ApplicationPoolName).ToList();
            appPoolNames.ForEach(iis7fix);
        }
开发者ID:NicolajLarsen,项目名称:PnP,代码行数:33,代码来源:WebRole.cs

示例5: 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

示例6: AddBindings

        public void AddBindings(string siteName, IEnumerable<Binding> bindings)
        {
            using (ServerManager manager = new ServerManager(_applicationHostPath))
              {
            Site site = manager.Sites.SingleOrDefault(s => s.Name == siteName);
            if (site == null)
            {
              throw new InvalidOperationException("Site does not exist: " + siteName);
            }

            bool configurationChanged = false;
            foreach (Binding binding in bindings)
            {
              bool bindingChanged = binding.AddTo(site.Bindings);
              if (bindingChanged)
              {
            configurationChanged = true;
              }
            }

            if (configurationChanged)
            {
              manager.CommitChanges();
            }
              }
        }
开发者ID:proNestorAps,项目名称:IisApplicationHostManager,代码行数:26,代码来源:ApplicationHostManager.cs

示例7: 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

示例8: 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

示例9: backgroundAssociatedSiteHttpRedirect_DoWork

 private void backgroundAssociatedSiteHttpRedirect_DoWork(object sender, DoWorkEventArgs e)
 {
     IEnumerable<TreeNode> selectedNoneWwwSiteNodes = e.Argument as IEnumerable<TreeNode>;
     int i = 1;
     int totalCount = selectedNoneWwwSiteNodes.Count();
     foreach (TreeNode siteNode in selectedNoneWwwSiteNodes)
     {
         if (!backgroundAssociatedSiteHttpRedirect.CancellationPending)
         {
             Node site = (Node)siteNode.Tag;
             bool enableChecked = true;
             string destination = string.Format("http://www.{0}", siteNode.Text);
             bool enableExactDestination = false;
             bool enableChildOnly = false;
             string httpResponseStatus = "永久(301)";
             try
             {
                 using (ServerManager serverManager = new ServerManager())
                 {
                     Configuration config = serverManager.GetWebConfiguration(site.Site.Name);
                     SetHttpRedirectElement(enableChecked, destination, enableExactDestination, enableChildOnly, httpResponseStatus, config);
                     string log = DateTime.Now.ToString() + ":" + string.Format("为站点 {0} 添加Http重定向,启用:{1},重定向目标:{2},定向到确切目标:{3},定向到非子目录中的内容:{4},状态代码:{5}", siteNode.Text, enableChecked, destination, enableExactDestination, enableChildOnly, httpResponseStatus);
                     backgroundAssociatedSiteHttpRedirect.ReportProgress(i * 100 / totalCount, log);
                     serverManager.CommitChanges();
                 }
             }
             catch (Exception exception)
             {
                 string log = DateTime.Now.ToString() + ":" + string.Format("为站点 {0} 添加Http重定向失败,错误详情如下", siteNode.Name) + exception.ToString();
                 backgroundSiteHttpRedirect.ReportProgress(i * 100 / totalCount, log);
             }
             i++;
         }
     }
 }
开发者ID:Brucezhang22,项目名称:IISConfiger,代码行数:35,代码来源:Form1.cs

示例10: 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

示例11: CreateAppPool

        /// <summary>
        /// 创建应用程序池
        /// </summary>
        /// <param name="appPoolName"></param>
        /// <param name="version"></param>
        /// <param name="isClassic"></param>
        public static void CreateAppPool(string appPoolName, string version, bool isClassic)
        {
            if (!DoesExistAppPool(appPoolName))
            {
                try
                {
                    DirectoryEntry newpool;
                    DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                    newpool = appPools.Children.Add(appPoolName, "IIsApplicationPool");
                    newpool.CommitChanges();
                }
                catch
                {
                    ServerManager iisManager = new ServerManager();
                    ApplicationPool appPool = iisManager.ApplicationPools.Add(appPoolName);
                    appPool.AutoStart = true;
                    appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
                    appPool.ManagedRuntimeVersion = "v2.0";
                    iisManager.CommitChanges();
                }

            }

            ServerManager manager = new ServerManager();

            manager.ApplicationPools[appPoolName].ManagedRuntimeVersion = version;
            manager.ApplicationPools[appPoolName].ManagedPipelineMode = isClassic ?
                ManagedPipelineMode.Classic : ManagedPipelineMode.Integrated;
            manager.ApplicationPools[appPoolName].ProcessModel.IdentityType = ProcessModelIdentityType.LocalSystem;
            manager.CommitChanges();
        }
开发者ID:jessiechenjz,项目名称:IISManager-ServerManage,代码行数:37,代码来源:IISUtil.cs

示例12: DeleteApplicationPool

 public static void DeleteApplicationPool(string poolName)
 {
     ServerManager iisManager = new ServerManager();
     ApplicationPool appPool = iisManager.ApplicationPools[poolName];
     iisManager.ApplicationPools.Remove(appPool);
     iisManager.CommitChanges();
 }
开发者ID:vivlong,项目名称:EventListWS,代码行数:7,代码来源:IISControlHelper.cs

示例13: CreateApplication

 public static void CreateApplication(string applicationPath, string folderPath, string applicationPoolName)
 {
     ServerManager iisManager = new ServerManager();
     iisManager.Sites[0].Applications.Add(applicationPath, folderPath);
     iisManager.Sites[0].Applications[applicationPath].ApplicationPoolName = applicationPoolName;
     iisManager.CommitChanges();
 }
开发者ID:vivlong,项目名称:EventListWS,代码行数:7,代码来源:IISControlHelper.cs

示例14: AddHttpsBinding

        private static void AddHttpsBinding(Session session, string installPath, X509Certificate2 cert, string certExportPath)
        {
            using (var mgr = new ServerManager())
            {
                session.Log("Searching for site in IIS.");
                var site = mgr.Sites.FirstOrDefault(s => s.Applications.Any(app => app.VirtualDirectories.Any(x => AreSameDirectory(x.PhysicalPath, installPath))));
                if(site == null)
                {
                    session.Log("Site not found.  This could be caused by the presence of IIS Express.");
                    throw new Exception("Could not find site.  This could be caused by the presence of IIS Express.");
                }

                session.Log("Site found ({0}), checking for https bindings.", site.Name);

                var httpsBinding = site.Bindings.FirstOrDefault(x => x.Protocol == "https" && x.BindingInformation.StartsWith("*:443"));
                if (httpsBinding != null)
                {
                    session.Log("Binding already present ({0}), it will not be changed.", httpsBinding.BindingInformation);
                    session.Log("Certificate sha1 fingerprint={0};", ToHex(httpsBinding.CertificateHash));
                    ExportPublicKey(session, certExportPath, httpsBinding.CertificateHash, httpsBinding.CertificateStoreName);
                    return;
                }

                session.Log("Usable https binding was not found, adding new one.");
                var storeName = new X509Store(StoreName.My, StoreLocation.LocalMachine).Name;
                site.Bindings.Add("*:443:", cert.GetCertHash(), storeName);
                ExportPublicKey(session, certExportPath, cert.GetCertHash(), storeName);
                session.Log("Certificate sha1 fingerprint={0};", ToHex(cert.GetCertHash()));
                mgr.CommitChanges();
                session.Log("Binding added.");
            }
        }
开发者ID:shayaneumar,项目名称:gabbar,代码行数:32,代码来源:CustomAction.cs

示例15: 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


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