using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using Microsoft.Web.Administration; //位于:C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll namespace Whir.Software.IISManager.IISManager
{
/// <summary>
/// IIS应用程序池辅助类
/// </summary>
public class AppPoolService
{
protected static string Host = "localhost"; /// <summary>
/// 取得所有应用程序池
/// </summary>
/// <returns></returns>
public static List<string> GetAppPools()
{
var appPools = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/AppPools", Host));
return (from DirectoryEntry entry in appPools.Children select entry.Name).ToList();
} /// <summary>
/// 取得单个应用程序池
/// </summary>
/// <returns></returns>
public static ApplicationPool GetAppPool(string appPoolName)
{
ApplicationPool app = null;
var appPools = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/AppPools", Host));
foreach (DirectoryEntry entry in appPools.Children)
{
if (entry.Name == appPoolName)
{
var manager = new ServerManager();
app = manager.ApplicationPools[appPoolName];
}
}
return app;
} /// <summary>
/// 判断程序池是否存在
/// </summary>
/// <param name="appPoolName">程序池名称</param>
/// <returns>true存在 false不存在</returns>
public static bool IsAppPoolExsit(string appPoolName)
{
bool result = false;
var appPools = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/AppPools", Host));
foreach (DirectoryEntry entry in appPools.Children)
{
if (entry.Name.Equals(appPoolName))
{
result = true;
break;
}
}
return result;
} /// <summary>
/// 删除指定程序池
/// </summary>
/// <param name="appPoolName">程序池名称</param>
/// <returns>true删除成功 false删除失败</returns>
public static bool DeleteAppPool(string appPoolName)
{
bool result = false;
var appPools = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/AppPools", Host));
foreach (DirectoryEntry entry in appPools.Children)
{
if (entry.Name.Equals(appPoolName))
{
try
{
entry.DeleteTree();
result = true;
break;
}
catch
{
result = false;
}
}
}
return result;
} /// <summary>
/// 创建应用程序池
/// </summary>
/// <param name="appPool"></param>
/// <returns></returns>
public static bool CreateAppPool(string appPool)
{
try
{
if (!IsAppPoolExsit(appPool))
{
var appPools = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/AppPools", Host));
DirectoryEntry entry = appPools.Children.Add(appPool, "IIsApplicationPool");
entry.CommitChanges();
return true;
}
}
catch
{
return false;
}
return false;
} /// <summary>
/// 编辑应用程序池
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
public static bool EditAppPool(ApplicationPool application)
{
try
{
if (IsAppPoolExsit(application.Name))
{
var manager = new ServerManager();
manager.ApplicationPools[application.Name].ManagedRuntimeVersion = application.ManagedRuntimeVersion;
manager.ApplicationPools[application.Name].ManagedPipelineMode = application.ManagedPipelineMode;
//托管模式Integrated为集成 Classic为经典
manager.CommitChanges();
return true;
}
}
catch
{
return false;
}
return false;
}
}
}

AppPoolService-IIS应用程序池辅助类(C#控制应用程序池操作)的更多相关文章

  1. C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏

    using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...

  2. [原]AppPoolService-IIS应用程序池辅助类(C#控制应用程序池操作)

    using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...

  3. IIS:连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解

    Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务.最初是Windows NT版本的可选 ...

  4. IIS连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解

    IIS:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池的最大工作进程数详解 iis性能指标的各种概念:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池 ...

  5. Azure Service Bus(二)在NET Core 控制台中如何操作 Service Bus Queue

    一,引言 上一篇讲到关于 Azure ServiceBus 的一些概念,讲到 Azure Service Bus(服务总线),其实也叫 "云消息服务",是微软在Azure 上提供的 ...

  6. IIS连接数、IIS并发连接数、IIS最大并发工作线程数、应用程序池的队列长度、应用程序池的

    IIS连接数 一般购买过虚拟主机的朋友都熟悉购买时,会限制IIS连接数,这边先从普通不懂代码用户角度理解IIS连接数 顾名思义即为IIS服务器可以同时容纳客户请求的最高连接数,准确的说应该叫" ...

  7. 你真的了解:IIS连接数、IIS并发连接数、IIS最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数 吗?

    原文链接:http://www.cnblogs.com/yinhaichao/p/4060209.html?utm_source=tuicool&utm_medium=referral 一般购 ...

  8. .net操作IIS,新建网站,新建应用程序池,设置应用程序池版本,设置网站和应用程序池的关联

    ServerManager类用来操作IIS,提供了很多操作IIS的API.使用ServerManager必须引用Microsoft.Web.Administration.dll,具体路径为:%wind ...

  9. 【jQuery】总结:筛选器、控制隐藏、操作元素style属性

    筛选器 -> http://blog.csdn.net/lijinwei112/article/details/6938134 常用到的: $("tr[id=ac_"+id+ ...

随机推荐

  1. 使用NPOI操作Excel(03、07)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using NPOI.SS. ...

  2. Eigenvectors and eigenvalues

    http://setosa.io/ev/eigenvectors-and-eigenvalues/ Explained Visually Tweet  By Victor Powell and Lew ...

  3. Google Protocol Buffer 的使用和原理

    Google Protocol Buffer 的使用和原理 Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,很适合做数据存储或 RPC 数据交换格式.它 ...

  4. 升级centos6.5系统的gcc为4.8.5的简易步骤

    Centos6.5_64位升级gcc为4.8.2的简易步骤 一.安装依赖包 yum install texinfo-tex flex zip mpfr-devel libgcc.i686 glibc- ...

  5. Jmeter安装使用教程

    解压jakarta-jmeter-X.X.zip至至如c盘:C:/jakarta-jmeter-2.2目录下.      桌面上选择“我的电脑”(右键),高级, 环境变量, 在“系统变量”---> ...

  6. 修改织梦默认提示"dedecms提示信息!"

    在使用dedecms搜索的时候如果搜索频率过快,经常会跳出一个提示窗口提示"管理员设定搜索时间间隔为*秒,请稍后再试!".怎么自定义Dedecms提示信息呢?让心存不轨的家伙少一个 ...

  7. 【视频】从零开始编写第一个PHP扩展

    Rango会讲解在Linux下从零开始写一个PHP扩展,并编译安装到PHP里,一直到执行扩展中的函数.包含的内容有: 为什么要开发PHP扩展 ext_skel工具的使用 修改config.m4 php ...

  8. Coursera台大机器学习课程笔记8 -- Linear Regression

    之前一直在讲机器为什么能够学习,从这节课开始讲一些基本的机器学习算法,也就是机器如何学习. 这节课讲的是线性回归,从使Ein最小化出发来,介绍了 Hat Matrix,要理解其中的几何意义.最后对比了 ...

  9. 基于 MeanShift 算法的目标跟踪问题研究

    参考:http://www.cnblogs.com/tornadomeet/archive/2012/03/15/2398769.html MeanShift 算法作为一种基于特征的跟踪方法,基本思想 ...

  10. overflow-x和overflow-y其中一个设置为visible时的奇怪现象

    当overflow-x和overflow-y其中一个设置为visible时,如果另一个不是visible,那么它会被自动重置为auto 看看效果先: 第一次遇到这个问题时,我还以为是chrome的一个 ...