[原]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 ...
- 【原】Java学习笔记007 - 流程控制
package cn.temptation; public class Sample01 { public static void main(String[] args) { // for循环 // ...
随机推荐
- hibernate提供的5种检索数据方式
一.五种检索数据方式 1.OID检索,即使用session.get或session.load通过类及指定id查询数据,如Customer c=(Customer)session.get("C ...
- HTTP负载测试——Tsung
参考资料:http://blog.jobbole.com/87509/ 如何生成每秒百万级别的 HTTP 请求? 在进行负责测试时要牢记一件重要的事:你能在 Linux 上建立多少个 socket 连 ...
- 面试题52:缺少i的乘积数组
vector<int> multiply(const vector<int>& A) { int len = A.size(); vector<); result ...
- 如何快速读懂大型C++程序代码
要搞清楚别人的代码,首先,你要了解代码涉及的领域知识,这是最重要的,不懂领域知识,只看代码本身,不可能搞的明白.其次,你得找各种文档:需求文档(要做什么),设计文档(怎么做的),先搞清楚你即将要阅读是 ...
- ASP.NET MVC学习笔记-----使用自定义的View Engine
我们都知道在ASP.NET MVC中自带了Razor View Engine,Razor十分的强大,可以满足我们绝大部分的需要.但是ASP.NET MVC的高度可扩展性,使我们可以使用自定义的View ...
- Java EE学习--Quartz基本用法
新浪博客完全不适合写技术类文章.本来是想找一个技术性的博客发发自己最近学的东西,发现博客园起源于咱江苏,一个非常质朴的网站,行,咱要养成好习惯,以后没事多总结总结经验吧.很多时候都在网上搜索别人的总结 ...
- CSS-3 Animation 的使用
在开始介绍Animation之前我们有必要先来了解一个特殊的东西,那就是"Keyframes",我们把他叫做"关键帧",玩过flash的朋友可能对这个东西并不会 ...
- L17 怎么向应用程序商店提交应用
原地址:https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/ApplicationD ...
- [LA3026]Period
[LA3026]Period 试题描述 For each prefix of a given string S with N characters (each character has an ASC ...
- c++ exports def文件
https://msdn.microsoft.com/zh-cn/library/hyx1zcd3(v=vs.80).aspx EXPORTS 引入了一个由一个或多个 definitions(导出的函 ...