private void CreateWebSite()
{
try
{
string installPath = "C:\\Program Files\\MyWeb";
string IISVirtualDirectory = "MyWeb";

var root = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT");
foreach (DirectoryEntry directoryEntry in root.Children)
{
if (directoryEntry.Name == IISVirtualDirectory)
{
try
{
root.Invoke("Delete", new[] { directoryEntry.SchemaClassName, IISVirtualDirectory });
root.CommitChanges();
}
catch (Exception)
{
}
}
}

DirectoryEntry de = root.Children.Add(IISVirtualDirectory, "IIsWebVirtualDir");
de.Properties["Path"][0] = installPath + @"\MyWebSite";
de.Invoke("AppCreate", true);
de.Properties["AppFriendlyName"][0] = IISVirtualDirectory;

//IIS下,将Framework自动对应到4.0版本。
Object[] mappings = (Object[])de.InvokeGet("ScriptMaps");

StringBuilder sb = new StringBuilder();
foreach (var a in mappings)
{
sb.Append(a + "\r\n");
}

ArrayList list = AddScriptArray();
de.CommitChanges();
}
catch
{
}
}

/// <summary>
/// IIS下,将Framework自动对应到4.0版本。
/// </summary>
/// <returns></returns>
private ArrayList AddScriptArray()
{
string specialFolder = "c:";
try
{
specialFolder = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 2);
}
catch
{

}
ArrayList list = new ArrayList();
list.Add(".asp," + specialFolder + @"\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE");
list.Add(".cer," + specialFolder + @"\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE");
list.Add(".cdx," + specialFolder + @"\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE");
list.Add(".asa," + specialFolder + @"\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE");
list.Add(".idc," + specialFolder + @"\WINDOWS\system32\inetsrv\httpodbc.dll,5,OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE");
list.Add(".shtm," + specialFolder + @"\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST");
list.Add(".shtml," + specialFolder + @"\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST");
list.Add(".stm," + specialFolder + @"\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST");
list.Add(".asax," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".ascx," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");

list.Add(".ashx," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".asmx," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".aspx," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".axd," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".vsdisco," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".rem," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".soap," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".config," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".cs," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".csproj," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");

list.Add(".vb," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".vbproj," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".webinfo," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".licx," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".resx," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".resources," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".master," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".skin," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".compiled," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".browser," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");

list.Add(".mdb," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".jsl," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".vjsproj," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".sitemap," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".msgx," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".ad," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".dd," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".ldd," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".sd," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".cd," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");

list.Add(".adprototype," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".lddprototype," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".sdm," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".sdmDocument," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".ldb," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".mdf," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".ldf," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".java," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".exclude," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".refresh," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");

list.Add(".xamlx," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
list.Add(".aspq," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".cshtm," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".cshtml," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5");
list.Add(".vbhtm," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".vbhtml," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
list.Add(".svc," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1");
list.Add(".xoml," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,1");
list.Add(".rules," + specialFolder + @"\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll,5");

return list;
}

转载自:http://www.cnblogs.com/takako_mu/archive/2012/01/11/2318803.html

c#创建ISS站点的更多相关文章

  1. 使用ASP在IIS创建WEB站点的函数

    程序代码: '=========================================================='函数介绍:创建WebSite'本函数使用ADSI,需要Adminis ...

  2. 利用OpenCms9提供的模块创建新站点

    OpenCms 9中提供b一个Demo,Demo使用了alkacon的bootstrap模板.如果已经安装了OpenCms 9,可以登陆http://localhost:8080/opencms/op ...

  3. 通过代码动态创建IIS站点

    对WebApi进行单元测试时,一般需要一个IIS站点,一般的做法,是通过写一个批处理的bat脚本来实现,其实通过编码,也能实现该功能. 主要有关注三点:应用程序池.Web站点.绑定(协议类型:http ...

  4. 使用appcmd命令创建iis站点及应用程序池

    参考文章:iis7 appcmd的基础命令及简单用法 验证环境:Windows 7    IIS7 AppCmd.exe工具所在目录 C:\windows\sytstem32\inetsrv\目录下, ...

  5. 使用PowerShell 创建SharePoint 站点

    使用PowerShell 创建SharePoint 站点         在SharePoint开发中,你应该学会使用PowerShell管理SharePoint网站.SharePoint Manag ...

  6. 阿里云nginx创建多站点

    最近开始用阿里云的vps,用了它的一键安装包安装了php环境,nginx的.下面记录创建多站点的心得. 首先php安装好后会自带安装一个phpwind的站点. 文件目录存放在 /alidata/www ...

  7. 在Yosemite中创建个人站点

    Yosemite变动很大,随之而来的就是一堆坑,之前在旧版OS中有效的方法在新版OS上已经不起作用了,创建个人站点就是一例. Mac OS内置Apache,安装目录在/etc/apache2/,etc ...

  8. c# sharepoint client object model 客户端如何创建中英文站点

    c# sharepoint client object model 客户端如何创建中英文站点 ClientContext ClientValidate = tools.GetContext(Onlin ...

  9. 如何创建Hexo站点的Tags和Categories默认页面

    安装Hexo的categories生成插件 1 $ npm install hexo-generator-category --save 安装Hexo的Tags生成插件 1 $ npm install ...

随机推荐

  1. mongoVUE1.5.3 破解方法

    MongoVUE是个免费软件,但超过15天后功能受限.可以通过删除以下注册表项来解除限制: [HKEY_CURRENT_USER\Software\Classes\CLSID\{B1159E65-82 ...

  2. CSS3弹性伸缩布局(二)——flex布局

    上一篇博客<CSS3弹性伸缩布局(一)——box布局>介绍了旧版本的box布局,而这篇博客将主要介绍最新版本的flex布局的基础知识. 新版本简介 新版本的Flexbox模型是2012年9 ...

  3. iOS宏定义

    1.__OBJC__宏定义作用 在.pch 文件中一般都会自动加上这句宏定义,表示宏内引用的文件确保只被使用Objective-C语言的文件所引用,保证引用关系的清晰.因为在一个OC工程中,可能包含. ...

  4. 序列化在Netty中的使用

    Java序列化的缺点 1.无法跨语言 对于Java序列化后的字节数组,别的语言无法进行反序列化 2.序列化后的码流过大 3.序列化性能低 使用JDK自带的序列化进行对象的传输 被传输的,实现了序列化接 ...

  5. 22Mybatis_订单商品数据模型_多对多查询以及对多对多查询的总结

    之前讲了一对一,一对多查询,这篇文章讲的是多对多. 先给出需求:查询用户及用户购买商品信息. 我们由之前的文章知道,这个需求是多对多的. 还是那个终止我们的mybatis所做的不管是之前的一对一还是一 ...

  6. py变量

        1, python以数据为主 x=2,是给数据2开辟了个空间, X指向了2 y=x ,即y指向了2 x=5 ,x重新赋值 但是y依旧是原来的

  7. java String.getBytes()编码问题——String.getBytes(charset)

    String的getBytes()方法是得到一个字串的字节数组,这是众所周知的.但特别要注意的是,本方法将返回该操作系统默认的编码格式的字节数组.如果你在使用这个方法时不考虑到这一点,你会发现在一个平 ...

  8. &10 基本数据结构——指针和对象的实现,有根树的表示

    #1,指针和对象的实现 如果所用的语言或者环境不支持指针和对象,那我们该怎么用数组来将其转化呢?实质上可以将这个问题的本质转化为数组和链表这两种数据结构的转换,准确来说,是将链表表示的数据用数组表示. ...

  9. ios 指南针

    指南针图片  IBOutlet UIImageView *compassView 1 #import "ViewController.h" #import <CoreLoca ...

  10. Java环境解析apk文件信息

    概述:Java解析apk文件,获取apk文件里的包名,版本号,图标文件等; 功能:可以提供给windows和linux平台使用; 原理:利用aapt.exe或者aapt这些anroid平台解析apk文 ...