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. HDU 4460 Friend Chains --BFS

    题意:问给定的一张图中,相距最远的两个点的距离为多少.解法:跟求树的直径差不多,从1 开始bfs,得到一个最远的点,然后再从该点bfs一遍,得到的最长距离即为答案. 代码: #include < ...

  2. MySQL数据库学习笔记(九)----JDBC的ResultSet接口(查询操作)、PreparedStatement接口重构增删改查(含SQL注入的解释)

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  3. Android数据存储(一)----SharedPreferences详解

    一.Android数据的存储方式: Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File:此外还有一种网络存储 ...

  4. Renderer.materials

    修改方法 meshBody.renderer.materials[].mainTexture= clothes[]; meshBody.renderer.materials[]=maters[]; 以 ...

  5. TestLink学习七:TestLink测试用例Excel转换XML工具

    TestLink对于测试用例的管理来说,是蛮强大的,但是在导入导出这块,功能有点弱,本文针对测试用例的导入,转载了一个Excel转换成xml工具. 1.根据到处的测试用例xml,定义一下我的Excel ...

  6. 使用List的addAll()方法请判空指针

    在写代码的时候经常会用到List,Set的addAll()方法,但是要注意addAll()方法不能传入空指针. package link.mengya.utils; import link.mengy ...

  7. [原创]CI持续集成系统环境---部署Jenkins完整记录

    Jenkins通过脚本任务触发,实现代码的自动化分发,是CI持续化集成环境中不可缺少的一个环节. 下面对Jenkins环境的部署做一记录. ------------------------------ ...

  8. redmine Windows装配

    原文:http://www.myexception.cn/windows/1219064.html redmine Windows安装 官方地址:http://www.redmine.org/ 所需环 ...

  9. C# 调用C++/MFC写的dll

    C#调用C++的非托管类的dll其实很简单基本就是固定的调用格式. dll的编写,首先是打开VS新建一个C++的控制台程序,下一步后选择dll以及空文档即可.然后就是添加一个类添加一个方法.方法排头固 ...

  10. nginx log的json格式:

    nginx log的json格式: 为了elk便于统计: yum安装nginx: log_format json '{"@timestamp": "$time_iso86 ...