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

Reading number is top 10 articles
SQL Server 2005数据加密技术应用研究_[SQL Server教程]
C#教程:Socket类的属性、方法使用实例
visual c++添加菜单命令处理函数
应用实例:ASP.Net中利用CSS实现多界面两法_.net资料_编程技术
C#教程:C#2.0 新特性 迭代器
ASP.NET模拟其他用户进行关机_.net资料_编程技术
C#中TreeView控件应用实例
SQL,Server,2008在商务智能上的三个优化_mssql学习_编程技术
无废话C#设计模式之七:Adapter_.net资料_编程技术
PHP技巧-巧用jquery达到无刷新删除效果_[PHP教程]
Reading number is top 10 pictures
Poor doll, hand job was caught the currently in effect by his dad
清纯性感的美眉1
最2B的公司制度
西游日记3
a pure sister
Startling Russian girl blind date scene2
Beauty ZhiHuiLin1
Sora aoi on twitter1
The cat shit
刘亦菲写真集1
Download software ranking
c#程序设计案例教程
C#COM编程指南
1400篇各类破解文章
WebService在.NET中的实战应用教学视频 → 第3集
Tram sex maniac 2 (H) rar bag11
Tram sex maniac 2 (H) rar bag6
Take off clothes to survival
Jinling thirteen stock
Tram sex maniac 2 (H) rar bag14
The Bermuda triangle3
delv published in(发表于) 2014/1/24 9:15:21 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教程]

IIS 6.0以后使用MetaBase.xml存储IIS信息,因此,可以直接修改这个文件即可。


代码如下: 很显然,这种方法比较复杂,不直观,而且需要停止IIS,影响现有网站。


///
/// 本方法创建一个站点(当然,创建虚拟目录也完全没有任何问题,做法类似),并设置IIS中ASP.NET版本为2.0
///

///
///
private void button1_Click(object sender, EventArgs e)
{
//站点名称和物理路径
String webSiteName = "mengxianhui";
String pathToRoot = @"c:\mengxianhui";
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");// Find unused ID value for new web site
int siteID = 1;
//得到现有的站点标识
foreach (DirectoryEntry entry in root.Children)
{
if (entry.SchemaClassName == "IIsWebServer")
{
int ID = Convert.ToInt32(entry.Name);

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

//利用配置文件的做法创建站点,需要先停止原来的服务,以便能够顺利写入数据
label1.Text = "正在停止服务……";
Application.DoEvents();
System.ServiceProcess.ServiceController mobServiceController3 = new System.ServiceProcess.ServiceController("IISAdmin");
foreach (System.ServiceProcess.ServiceController dependentService in mobServiceController3.DependentServices)
{
switch (dependentService.Status)
{
case ServiceControllerStatus.Stopped:
break;

case ServiceControllerStatus.StopPending:
dependentService.WaitForStatus(ServiceControllerStatus.Stopped);
break;

default:
dependentService.Stop();
dependentService.WaitForStatus(ServiceControllerStatus.Stopped);
break;
}

}
if (mobServiceController3.Status != ServiceControllerStatus.Stopped)
{
mobServiceController3.Stop();
mobServiceController3.WaitForStatus(ServiceControllerStatus.Stopped);
}
//确保服务完全停止
label1.Text = "停止服务完成!";
Application.DoEvents();
String ConfigPath = System.Environment.SystemDirectory + @"\inetsrv\MetaBase.xml";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(ConfigPath);

System.Xml.XmlNamespaceManager xnm = new System.Xml.XmlNamespaceManager(doc.NameTable);
xnm.AddNamespace("mxh", "urn:microsoft-catalog:XML_Metabase_V64_0");

//得到最大的网站的标识,要在其后面加入节点
string SiteLocation = "/LM/W3SVC/" + (siteID - 1);
System.Xml.XmlNode LastWebServer = doc.SelectSingleNode("/mxh:configuration/mxh:MBProperty/mxh:IIsWebVirtualDir[@Location='" + SiteLocation + "/root']", xnm);
if (LastWebServer == null)
{
MessageBox.Show("没有现有的 Web 服务器。");
doc = null;
return;
}

//找到AdminACL设置,每次都是变化的 -_-!
System.Xml.XmlNode LastWebServerFilter = doc.SelectSingleNode("/mxh:configuration/mxh:MBProperty/mxh:IIsFilters[@Location='" + SiteLocation + "/filters']/@AdminACL", xnm);
if (LastWebServer == null)
{
MessageBox.Show("没有现有的 Web 服务器 filters。");
doc = null;
return;
}

String LastWebServerFilterAdminAcl = LastWebServerFilter.Value;

//创建新站点
label1.Text = "创建新站点……";
Application.DoEvents();
String NewSiteID = "/LM/W3SVC/" + siteID.ToString();
System.Xml.XmlNode NewWebServer = doc.CreateNode(System.Xml.XmlNodeType.Element, "", "IIsWebServer", "urn:microsoft-catalog:XML_Metabase_V64_0");
System.Xml.XmlAttribute NewWebServerLocation = doc.CreateAttribute("Location");
NewWebServerLocation.Value = NewSiteID;
NewWebServer.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("AuthFlags");
NewWebServerLocation.Value = "0";
NewWebServer.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("ServerAutoStart");
NewWebServerLocation.Value = "TRUE";
NewWebServer.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("ServerBindings");
NewWebServerLocation.Value = ":802:";
NewWebServer.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("ServerComment");
NewWebServerLocation.Value = webSiteName;
NewWebServer.Attributes.Append(NewWebServerLocation);
LastWebServer.ParentNode.InsertAfter(NewWebServer, LastWebServer);

System.Xml.XmlNode NewWebServerFilter = doc.CreateNode(System.Xml.XmlNodeType.Element, "", "IIsFilters", "urn:microsoft-catalog:XML_Metabase_V64_0");
NewWebServerLocation = doc.CreateAttribute("Location");
NewWebServerLocation.Value = NewSiteID + "/filters";
NewWebServerFilter.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("AdminACL");
NewWebServerLocation.Value = LastWebServerFilterAdminAcl;
NewWebServerFilter.Attributes.Append(NewWebServerLocation);

NewWebServer.ParentNode.InsertAfter(NewWebServerFilter, NewWebServer);

System.Xml.XmlNode IIsWebVirtualDir = doc.CreateNode(System.Xml.XmlNodeType.Element, "", "IIsWebVirtualDir", "urn:microsoft-catalog:XML_Metabase_V64_0");
NewWebServerLocation = doc.CreateAttribute("Location");
NewWebServerLocation.Value = NewSiteID + "/root";
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("AccessFlags");
NewWebServerLocation.Value = "AccessRead | AccessScript";
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("AppFriendlyName");
NewWebServerLocation.Value = "默认应用程序";
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("AppIsolated");
NewWebServerLocation.Value = "2";
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("AppRoot");
NewWebServerLocation.Value = NewSiteID + "/Root";
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("AuthFlags");
NewWebServerLocation.Value = "AuthAnonymous | AuthNTLM";
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

//关于权限,可以任意组合
NewWebServerLocation = doc.CreateAttribute("DirBrowseFlags");
NewWebServerLocation.Value = "DirBrowseShowDate | DirBrowseShowTime | DirBrowseShowSize | DirBrowseShowExtension | DirBrowseShowLongDate | EnableDefaultDoc";
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

NewWebServerLocation = doc.CreateAttribute("Path");
NewWebServerLocation.Value = pathToRoot;
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

//为安全起见,下面的系统文件夹需要使用程序的方法获取,如System.Environment.SystemDirectory,和System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
//这里为了简单期间,直接写入
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";

NewWebServerLocation = doc.CreateAttribute("ScriptMaps");
NewWebServerLocation.Value = ScriptMaps;
IIsWebVirtualDir.Attributes.Append(NewWebServerLocation);

NewWebServerFilter.ParentNode.InsertAfter(IIsWebVirtualDir, NewWebServerFilter);
doc.Save(ConfigPath);
doc = null;

label1.Text = "创建站点完成!";
mobServiceController3 = null;
mobServiceController3 = new System.ServiceProcess.ServiceController("w3svc");
mobServiceController3.Start();
mobServiceController3.WaitForStatus(ServiceControllerStatus.Running);
mobServiceController3 = null;
label1.Text = "恭喜你,全部工作完成!";
MessageBox.Show("恭喜你,全部工作完成!");
}








添加到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.