using System; using System.Net; using System.IO; using System.Timers; using System.Threading; using System.Diagnostics; using System.Xml; using System.Text.RegularExpressions; using System.Collections; using System.Data; using System.Data.SqlClient; using System.ServiceProcess; using Microsoft.Web.Administration; //添加程序集>扩展>引用
/// <summary> /// 开始执行设置IIS站点和程序池 /// </summary> /// <param name="Task_Channel">操作渠道</param> public void SetIIS() { var sm = new ServerManager(); try { Log.WriteTextLog("SetIIS.Service", "SetIIS", "SetIIS"); string str = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string AppPoolName = "SFSAppPool"; //程序池名称 string WebSiteName = "Default"; //iis 注意是父级 站点名称 var pool = sm.ApplicationPools[AppPoolName]; if (pool != null) { if (pool.State == ObjectState.Started) { pool.Stop(); Log.WriteTextLog("SetIIS.Service", "ApplicationPools", "检测到应用池" + AppPoolName + "停止服务"); Thread.Sleep(3000); } if (pool.State == ObjectState.Stopped) { pool.Start(); Log.WriteTextLog("SetIIS.Service", "ApplicationPools", "正在启动应用池" + AppPoolName); Thread.Sleep(3000); } if (pool.Start() == ObjectState.Started) { Log.WriteTextLog("SetIIS.Service", "ApplicationPools", "成功启动应用池" + AppPoolName); } else { Log.WriteTextLog("SetIIS.Service", "ApplicationPools", "启动应用池" + AppPoolName + "失败"); Thread.Sleep(3000); pool.Start(); } Thread.Sleep(50); } var site = sm.Sites[WebSiteName]; if (site != null) { if (site.State == ObjectState.Started) { site.Stop(); Log.WriteTextLog("SetIIS.Service", "Sites", "检测到网站" + WebSiteName + "停止服务"); Thread.Sleep(3000); } if (site.State == ObjectState.Stopped) { site.Start(); Log.WriteTextLog("SetIIS.Service", "Sites", "正在启动网站" + WebSiteName); Thread.Sleep(3000); } if (site.Start() == ObjectState.Started) { Log.WriteTextLog("SetIIS.Service", "Sites", "成功启动网站" + WebSiteName); } else { Log.WriteTextLog("SetIIS.Service", "Sites", "启动网站" + WebSiteName + "失败"); Thread.Sleep(3000); site.Start(); } Thread.Sleep(50); } } catch (WebException ex) { string stacktrace = ex.StackTrace;//获得详细的错误位置 Log.WriteTextLog("SetIIS.Service.Error", "WebException", stacktrace + "##" + ex.Message); } finally { if(sm != null) { sm.Dispose(); } if(sm != null) { sm = null; } //回收内存 Thread.Sleep(16); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!