C#操作IIS应用程序池的配置

八月 17, 2010 | 标签 | 浏览
评论 0
本文使用.net来操作IIS的配置,看代码:
IIS6.0以上版本,查看IIS的属性
http://msdn.microsoft.com/en-us/library/ms525539.aspx
我们查看metabase.xml(windows/system32/intesrv目录)

<IIsApplicationPool    Location ="/LM/W3SVC/AppPools/DefaultAppPool"    
        AppPoolAutoStart="TRUE"    
        PeriodicRestartMemory="2000"  //最大虚拟内存MB    
        PeriodicRestartPrivateMemory="1000" //最大占用内存MB    
        PeriodicRestartRequests="1000" //请求数    
        PeriodicRestartSchedule="07:50  //自动回收时间    
            12:00    
            20:00"    
    >    
</IIsApplicationPool>  

使用c#运用ASDI操作管理程序池代码如下:

protected void StartStopRecycleApp(string method)   
{   
    string AppPoolName = "DefaultAppPool";   
   
    try   
    {   
        DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");   
        DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool");   
   
        findPool.Properties["PeriodicRestartMemory"].Value = (object)512000;//设置最大虚拟内存占有   
        findPool.Properties["PeriodicRestartPrivateMemory"].Value = (object)200000;//设置最大物理内存占有   
        string[] strPamer = { "07:50", "12:00", "20:00" };   
        findPool.Properties["PeriodicRestartSchedule"].Value = (object)strPamer;//设置自动回收时间   
        findPool.CommitChanges();   
        appPool.CommitChanges();   
        appPool.Close();   
    }   
    catch (Exception ex)   
    {   
        MessageBox.Show(ex.Message);   
        //lbMsg.Text = string.Format("应用程序池{0}{2}失败:{1}", AppPoolName, ex.Message, method);   
    }   
}   


    相关文章:



发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。