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+ ...
随机推荐
- hdu 1257 最少拦截系统(贪心)
解题思路:[要充分理解题意,不可断章取义] 贪心:每个防御系统要发挥其最大性能, 举例: Input : 9 389 207 155 300 299 170 155 158 65 Output: 2 ...
- day4作业之信息表
实在是太low了,终究是自己写的,记录下 #!/usr/bin/env python # coding=utf8 import os, re #这里我把查询这块分为3个函数了,纠结了很久是放一起还是分 ...
- Dynamic Virtual Channels
refer http://blogs.msdn.com/b/rds/archive/2007/09/20/dynamic-virtual-channels.aspx An important goal ...
- nginx负载均衡器处理session共享的几种方法(转)
1) 不使用session,换作cookie 能把session改成cookie,就能避开session的一些弊端,在从前看的一本J2EE的书上,也指明在集群系统中不能用session,否则惹出祸端来 ...
- aop注解
注解 xml的直接配置 <aop:config proxy-target-class="false"> //切入点 <aop:pointcut expressio ...
- C++构造函数详解及显式调用构造函数
来源:http://www.cnblogs.com/xkfz007/archive/2012/05/11/2496447.html c++类的构造函数详解 ...
- 反射中 GetCustomAttributes
public abstract object[] GetCustomAttributes(bool inherit); 这是GetCustomAttributes方法的一个重载,参数为bool类型返回 ...
- 设置dom元素可拖动,支持ie5+
摘要: 最近在项目中要做一个图片预览的功能,这时候会遇到用户上传很大的图片,已经超出视图界面.最终决定做一个在固定宽和高的位置,用户可以拖动图片查看.所以自己就写了一个支持ie5+,chrome,Fi ...
- 神秘代码让iPhone微信闪退的解决方法
14号晚,很多人的微信朋友圈中出现了这样几句话“听说苹果手机点全文就会闪退”,下方有好几行空白,需要点击“全文”才能看到,但是一旦你是在iPhone手机微信上点击“原文”后就直接闪退了,而用Andro ...
- LayoutComponent类,用于layout的组件类。 LayoutComponent保存的所有用于布局的数据。
LayoutComponent () 默认构造函数 更多... ~LayoutComponent () 默认的析构函数 更多... CREATE_FUNC (LayoutC ...