C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏
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.InteralServerManage.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;
}
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏的更多相关文章
- 修改MS SQL忽略大小写 分类: SQL Server 数据库 2015-06-19 09:18 34人阅读 评论(0) 收藏
第一步:数据库->属性->选项->限制访问:SINGLE_USER 第二步:ALTER DATABASE [数据库名称] collate Chinese_PRC_CI_AI 第三步: ...
- *** glibc detected *** malloc(): memory corruption 分类: C/C++ Linux 2015-05-14 09:22 37人阅读 评论(0) 收藏
*** glibc detected *** malloc(): memory corruption: 0x09eab988 *** 发现是由于memset越界写引起的. 在Linux Server上 ...
- 哈希-4 Values whose Sum is 0 分类: POJ 哈希 2015-08-07 09:51 3人阅读 评论(0) 收藏
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 17875 Accepted: ...
- 哈希-Gold Balanced Lineup 分类: POJ 哈希 2015-08-07 09:04 2人阅读 评论(0) 收藏
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13215 Accepted: 3873 ...
- opnet的simple_source模块学习 分类: opnet 2014-05-18 09:50 170人阅读 评论(0) 收藏
simple_source模块可以在外部设置的属性 有四个局部统计量,分别为产生的bit速率.包速率.包大小,包间隔 状态机为三个非强制对象,在头文件里定义了自中断和转移条件. /*Include f ...
- OC基础:内存(内存管理) 分类: ios学习 OC 2015-06-25 16:50 73人阅读 评论(0) 收藏
自动释放池: @autoreleasepool { } 内存管理机制 谁污染,谁治理 垃圾回收机制:gc(Garbage collection),由系统管理内存,开发人员不需要管理. OC ...
- XHTML 结构化:使用 XHTML 重构网站 分类: C1_HTML/JS/JQUERY 2014-07-31 15:58 249人阅读 评论(0) 收藏
http://www.w3school.com.cn/xhtml/xhtml_structural_01.asp 我们曾经为本节撰写的标题是:"XHTML : 简单的规则,容易的方针.&qu ...
- Mahout快速入门教程 分类: B10_计算机基础 2015-03-07 16:20 508人阅读 评论(0) 收藏
Mahout 是一个很强大的数据挖掘工具,是一个分布式机器学习算法的集合,包括:被称为Taste的分布式协同过滤的实现.分类.聚类等.Mahout最大的优点就是基于hadoop实现,把很多以前运行于单 ...
- iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏
youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...
随机推荐
- python wraps
用代码说明问题: def d(f): def _d(*args, **kwargs): print f.__name__, ' is called' f(*args, **kwargs) return ...
- Apache和PHP的安装
最近看了一些教科书,可能是印刷的缘故,只是一个空格没有打印,再加上网上的很多博客文章只是顺手转载,并没有仔细的检查,还有php和apache之间的版本问题,害得我花了4,5小时的时间才搞定环境的搭配. ...
- 统计代码git提交的行数
$ git log --author="$(git config --get user.name)" --pretty=tformat: --numstat | gawk '{ a ...
- gpt格式下通过U盘装win7系统
首先下好一个64位的win7系统,可以是ghost版的,然后放到你的U盘,在U盘的根目录下添加bootmgr.efi,bootx64.efi.shell.efi这几个文件,其它都不要管,重启,你就在g ...
- 二叉树节点个数题目[n0,n1,n2]
若完全二叉树的节点个数为2N-1,则叶节点个数为() A)N-1 B)2×N C)2N-1 D)2N解析: 结点拥有的子树数为结点的度 证明 ...
- <转>VPN技术原理
原文地址:VPN技术原理 VPN,Virtual Private Network(虚拟专用 网络),被定义为通过一个公用网络(通常是因特网)建立一个临时的.安全的连接,是一条穿过公用网络的安全.稳定的 ...
- maven加载本地oracle的JDBC驱动
转载自:http://blog.csdn.net/qicyt1812/article/details/13019933 由于oracle商业版权问题,maven不能通过中心资源库直接下载jar包,如果 ...
- 表单中Readonly和Disabled的区别(转载)
Readonly和Disabled是用在表单中的两个属性,它们都能够做到使用户不能够更改表单域中的内容.但是它们之间有着微小的差别,总结如下: Readonly只针对input(text / pass ...
- 【leetcode】Maximal Rectangle (hard)★
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
- 【编程题目】如何对n个数进行排序,要求时间复杂度O(n),空间复杂度O(1)
转自:http://blog.csdn.net/vast_sea/article/details/8167968 看上去似乎任何已知的算法都无法做到,如果谁做到了,那么所有的排序方法:QuickSor ...