[點晴永久免費OA]C#創(chuàng)建并設(shè)置IIS網(wǎng)站應(yīng)用程序池
/// <summary>
/// 創(chuàng)建應(yīng)用程序池 IIS 7 默認是 FrameWork 4.0 集成模式
/// </summary>
/// <param name="appPoolName"></param>
/// <param name="maxProcesses">最大進程數(shù)</param>
/// <param name="queueLength">隊列長度</param>
/// <param name="type">0為集成模式1為經(jīng)理模式</param>
public static bool createAppPool7(string appPoolName, long maxProcesses,long queueLength,string type)
{
try
{
ServerManager sm = new ServerManager();
//判斷是否存在應(yīng)用程序池
ApplicationPool appPool = sm.ApplicationPools[appPoolName];
if (appPool == null)
{
sm.ApplicationPools.Add(appPoolName);
ApplicationPool apppool = sm.ApplicationPools[appPoolName];
if ("0".Equals(type))
{
apppool.ManagedPipelineMode = ManagedPipelineMode.Integrated;//托管管道為集成模式 ManagedPipelineMode.Classic為經(jīng)典模式
}
else {
apppool.ManagedPipelineMode = ManagedPipelineMode.Classic;//托管管道為經(jīng)典模式 ManagedPipelineMode.Classic為經(jīng)典模式
}
apppool.ManagedRuntimeVersion = "v4.0"; //當設(shè)置錯誤時,會在應(yīng)用程序中創(chuàng)建一個不存在的版本,不會報錯
//應(yīng)當檢測當前電腦是否安裝 FrameWork 4.0 ,并處理沒有安裝時該怎么辦
//apppool.QueueLength
apppool.Recycling.DisallowOverlappingRotation = false;
apppool.Recycling.PeriodicRestart.Time = TimeSpan.fromMinutes(0);
apppool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("23:00:00"));
apppool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("06:00:00"));
apppool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("12:30:00"));
apppool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("18:00:00"));
apppool.Recycling.LogEventOnRecycle = RecyclingLogEventOnRecycle.Memory
| RecyclingLogEventOnRecycle.Requests
| RecyclingLogEventOnRecycle.ConfigChange
| RecyclingLogEventOnRecycle.IsapiUnhealthy
| RecyclingLogEventOnRecycle.OnDemand
| RecyclingLogEventOnRecycle.PrivateMemory
| RecyclingLogEventOnRecycle.Schedule
| RecyclingLogEventOnRecycle.Time;
apppool.Recycling.PeriodicRestart.Memory = 40960000;
apppool.Recycling.PeriodicRestart.PrivateMemory= 0;
apppool.ProcessModel.IdleTimeout = TimeSpan.fromMinutes(0);
apppool.ProcessModel.MaxProcesses= maxProcesses;
apppool.ProcessModel.ShutdownTimeLimit = TimeSpan.fromSeconds(120);//關(guān)閉時間限制設(shè)置為120秒
apppool.QueueLength = queueLength;
apppool.Cpu.Limit = 80000;
apppool.Cpu.Action=ProcessorAction.KillW3wp;
apppool.Failure.RapidFailProtection = false;
apppool.AutoStart = true;
sm.CommitChanges();
apppool.Recycle();
}
else
{
//appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;//托管管道為集成模式 ManagedPipelineMode.Classic為經(jīng)典模式
if ("0".Equals(type))
{
appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;//托管管道為集成模式 ManagedPipelineMode.Classic為經(jīng)典模式
}
else
{
appPool.ManagedPipelineMode = ManagedPipelineMode.Classic;//托管管道為經(jīng)典模式 ManagedPipelineMode.Classic為經(jīng)典模式
}
appPool.ManagedRuntimeVersion = "v4.0"; //當設(shè)置錯誤時,會在應(yīng)用程序中創(chuàng)建一個不存在的版本,不會報錯
//應(yīng)當檢測當前電腦是否安裝 FrameWork 4.0 ,并處理沒有安裝時該怎么辦
appPool.Recycling.DisallowOverlappingRotation = false;
appPool.Recycling.PeriodicRestart.Time = TimeSpan.fromMinutes(0);
appPool.Recycling.PeriodicRestart.Schedule.Clear();
appPool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("23:00:00"));
appPool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("06:00:00"));
appPool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("12:30:00"));
appPool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("18:00:00"));
appPool.Recycling.LogEventOnRecycle = RecyclingLogEventOnRecycle.Memory
| RecyclingLogEventOnRecycle.Requests
| RecyclingLogEventOnRecycle.ConfigChange
| RecyclingLogEventOnRecycle.IsapiUnhealthy
| RecyclingLogEventOnRecycle.OnDemand
| RecyclingLogEventOnRecycle.PrivateMemory
| RecyclingLogEventOnRecycle.Schedule
| RecyclingLogEventOnRecycle.Time;
appPool.Recycling.PeriodicRestart.Memory = 40960000;
appPool.Recycling.PeriodicRestart.PrivateMemory = 0;
appPool.ProcessModel.IdleTimeout = TimeSpan.fromMinutes(0);
appPool.ProcessModel.MaxProcesses = maxProcesses;
appPool.ProcessModel.ShutdownTimeLimit = TimeSpan.fromSeconds(120);//關(guān)閉時間限制設(shè)置為120秒
appPool.QueueLength = queueLength;
appPool.Cpu.Limit = 80000;
appPool.Cpu.Action = ProcessorAction.KillW3wp;
appPool.Failure.RapidFailProtection = false;
appPool.AutoStart = true;
sm.CommitChanges();
appPool.Recycle();
}
}
catch
{
return false;
}
return true;
}
該文章在 2023/1/19 0:49:15 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |