All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP生成WML文件源代码样本_[XML教程]
ASP.Net下两种全局变量的设置和读取方法_[Asp.Net教程]
PHP也可以当成Shell,Script进行使用_php资料_编程技术
Sql,server,CLR自定义类型存储对象_[SQL,Server教程]
ASP.NET,2.0中的Web和HTML服务器控件_[Asp.Net教程]
一个表,有金额,有日期,如何按月统计金额_[SQL Server教程]
手工卸载SQL Server 2000数据库_[SQL Server教程]
PHP技巧:关于cookie和session的分析_[PHP教程]
PHP能得到你是从什么页面过来的,referer的用处_php资料_编程技术
php之str_replace_php资料_编程技术
Reading number is top 10 pictures
青春清纯美女大集合2
西方气质的东方美女3
鸡也看毛片
美洲杯宝贝的雨中风情2
Sora aoi in China2
Sora aoi on twitter1
Average female college students3
青春清纯美女大集合4
Get girl by your hand
网络游戏与脑残
Download software ranking
Professional killers2 data package
Boxer's Top ten classic battle1
虚拟机汉化软件
网络管理员第三版
Sora aoi, the nurse, uniform ,nursing assistant
Tram sex maniac 2 (H) rar bag14
Tram sex maniac 2 (H) rar bag5
c#程序设计案例教程
I'm come from Beijing1
网络管理员第三版
delv published in(发表于) 2014/1/24 9:15:23 Edit(编辑)
利用C#创建,IIS,站点并设置.NET,Framework版本为ASP.NET,2.0,的方法,二_[Asp.Net教程]

利用C#创建,IIS,站点并设置.NET,Framework版本为ASP.NET,2.0,的方法,二_[Asp.Net教程]

利用C#创建 IIS 站点并设置.NET Framework版本为ASP.NET 2.0 的方法 二_[Asp.Net教程]

利用.NET Framework提供的System.DirectoryServices.DirectoryEntry类可以轻松创建IIS站点,并将站点设置为ASP.NET 2.0版本。无疑,这种方法与前面的那个方法相比较,是比较好的。一下代码需要注意的地方是:


1,没有做路径检查,这个很简单;
2,没有做端口存在的检查,这个也不是很复杂;
3,ScriptMapsList数组是为了简单起见,直接从字符串进行分解出来,这个需要注意你自己的应用;
4;更多IIS权限处理,可根据需要进行添加。


本方法代码如下:


string ScriptMaps = @".asp,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.cer,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.cdx,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.asa,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.idc,C:\WINDOWS\system32\inetsrv\httpodbc.dll,5,GET,POST
.shtm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
.shtml,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
.stm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
.asax,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ascx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ashx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.asmx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.aspx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.axd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.vsdisco,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.rem,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.soap,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.config,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.cs,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.csproj,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.vb,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.vbproj,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.webinfo,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.licx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.resx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.resources,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.xoml,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.rules,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.master,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.skin,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.compiled,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.browser,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.mdb,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.jsl,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.vjsproj,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.sitemap,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.msgx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.ad,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.dd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ldd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.sd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.cd,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.adprototype,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.lddprototype,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.sdm,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.sdmDocument,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ldb,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.svc,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.mdf,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ldf,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.java,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.exclude,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.refresh,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG";

String[] ScriptMapsList = System.Text.RegularExpressions.Regex.Split(ScriptMaps, "\r\n");


///注意:这里没有进行进行端口存在的检查
// Access Flags
const int MD_ACCESS_READ = 0x00000001; //Allow read access.
const int MD_ACCESS_SCRIPT = 0x00000200; // Allow script execution.


string entPath = "IIS://localhost/w3svc";
System.DirectoryServices.DirectoryEntry rootEntry = new System.DirectoryServices.DirectoryEntry(entPath);
int siteID = 1;
//得到现有的站点标识
foreach (System.DirectoryServices.DirectoryEntry entry in rootEntry.Children)
{
if (entry.SchemaClassName == "IIsWebServer")
{
int ID = Convert.ToInt32(entry.Name);

if (ID >= siteID)
{
siteID = ID + 1;
}
}
}

System.DirectoryServices.DirectoryEntry newSiteEntry = rootEntry.Children.Add(siteID.ToString(), "IIsWebServer");
newSiteEntry.Properties["ServerBindings"].Value = ":8001:";
newSiteEntry.Properties["ServerComment"].Value = "mengxianhui2";
newSiteEntry.CommitChanges();
System.DirectoryServices.DirectoryEntry vDirEntry = newSiteEntry.Children.Add("root", "IIsWebVirtualDir");
vDirEntry.Properties["Path"].Value = @"C:\mengxianhui";
//System.Collections.ArrayList ScriptMapsList = new System.Collections.ArrayList();
//ScriptMapsList.Add(@".aspx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".asax,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".svc,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".msgx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".config,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".ascx,c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
vDirEntry.Properties["ScriptMaps"].Value = ScriptMapsList;
vDirEntry.Properties["AppFriendlyName"][0] = "孟宪会的网站";
vDirEntry.Properties["AppIsolated"][0] = 2;
vDirEntry.Properties["AccessFlags"][0] = MD_ACCESS_READ | MD_ACCESS_SCRIPT;
vDirEntry.Properties["AppRoot"][0] = "LM/W3SVC/" + siteID + "/Root";
vDirEntry.CommitChanges();
newSiteEntry.CommitChanges();
MessageBox.Show("创建完成!");

来源:孟宪会的blog







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.