AppPoolService-IIS应用程序池辅助类(C#控制应用程序池操作)
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#控制应用程序池操作)的更多相关文章
- C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏
using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...
- [原]AppPoolService-IIS应用程序池辅助类(C#控制应用程序池操作)
using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...
- IIS:连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解
Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务.最初是Windows NT版本的可选 ...
- IIS连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解
IIS:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池的最大工作进程数详解 iis性能指标的各种概念:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池 ...
- Azure Service Bus(二)在NET Core 控制台中如何操作 Service Bus Queue
一,引言 上一篇讲到关于 Azure ServiceBus 的一些概念,讲到 Azure Service Bus(服务总线),其实也叫 "云消息服务",是微软在Azure 上提供的 ...
- IIS连接数、IIS并发连接数、IIS最大并发工作线程数、应用程序池的队列长度、应用程序池的
IIS连接数 一般购买过虚拟主机的朋友都熟悉购买时,会限制IIS连接数,这边先从普通不懂代码用户角度理解IIS连接数 顾名思义即为IIS服务器可以同时容纳客户请求的最高连接数,准确的说应该叫" ...
- 你真的了解:IIS连接数、IIS并发连接数、IIS最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数 吗?
原文链接:http://www.cnblogs.com/yinhaichao/p/4060209.html?utm_source=tuicool&utm_medium=referral 一般购 ...
- .net操作IIS,新建网站,新建应用程序池,设置应用程序池版本,设置网站和应用程序池的关联
ServerManager类用来操作IIS,提供了很多操作IIS的API.使用ServerManager必须引用Microsoft.Web.Administration.dll,具体路径为:%wind ...
- 【jQuery】总结:筛选器、控制隐藏、操作元素style属性
筛选器 -> http://blog.csdn.net/lijinwei112/article/details/6938134 常用到的: $("tr[id=ac_"+id+ ...
随机推荐
- spring属性依赖注入
一.构造方法方式注入 1.项目结构如下: 2.新建Customer类 package hjp.spring.attributeinject; public class Customer { priva ...
- --hdu 1231 最大连续子序列(动态规划)
AC code: #include<stdio.h> int a[100005]; int main(void) { int n,i; int sum,maxn,tem,s,e,flag; ...
- XSS 自动化检测 Fiddler Watcher & x5s & ccXSScan 初识
一.标题:XSS 自动化检测 Fiddler Watcher & x5s & ccXSScan 初识 automated XSS testing assistant 二.引言 ...
- 复选框全选、全不选和反选的效果实现VIEW:1592
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- Android Studio-AndroidStudio目录结构
最近,Google已经打算废弃Eclipse,而要大力支持他的亲生儿子AndroidStudio了,已经不在维护Eclipse了,也就是说在Eclipse上面出了什么问题,Google已经不在会管了, ...
- sublime Text 3实用功能和常用快捷键收集
下面是我通过网上视频教程或文本资料学习sublime Text3时收集的一些实用功能和常用快捷键,现在分享出来,如果还有其它的好用的功能可以在下面留言,以便互相学习. PS:ST3在Mac OX与Wi ...
- 获取window窗口大小
窗口大小 跨浏览器确定一个窗口的大小不是一件简单的事.IE9+.Firefox.Safari.Opera和Chrome均为此提供了4个属性:innerWidth.innerHeight.outerWi ...
- vim显示行号
在Linux环境下的编辑器有vi.vim.gedit等等.进入这些编辑器之后,为了方便我们需要编辑器显示出当前的行号,可偏偏编辑器默认是不会显示行号的.我们有二种办法可以解决: 第一种是,手动显示:在 ...
- Linux文件权限管理(持续更新)
文章是从我的个人博客上粘贴过来的, 大家也可以访问我的主页 www.iwangzheng.com 以root身份登录linux以后, ls -al 可以看到 -rw-rw-r-- 1 wangzhe ...
- chm文件打开空白无内容的解决办法
今天下载了个chm文件,但是打开空白,也没显示什么内容,经过一番研究之后终于可以正常显示了,下面把解决办法分享出来供大家参考下,谢谢. 工具/原料 windows7系统 chm文件 方法/步骤 ...