久久中文视频-久久中文网-久久中文亚洲国产-久久中文字幕久久久久-亚洲狠狠成人综合网-亚洲狠狠婷婷综合久久久久

以文本方式查看主題

-  曙海教育集團(tuán)論壇  (http://www.xinguifushi.cn/bbs/index.asp)
--  Microsoft.NET Framework  (http://www.xinguifushi.cn/bbs/list.asp?boardid=78)
----  利用C#創(chuàng)建 IIS 站點(diǎn)并設(shè)置.NET Framework版本為ASP.NET 2.0 的方法 一  (http://www.xinguifushi.cn/bbs/dispbbs.asp?boardid=78&id=2616)

--  作者:wangxinxin
--  發(fā)布時(shí)間:2010-12-15 8:43:44
--  利用C#創(chuàng)建 IIS 站點(diǎn)并設(shè)置.NET Framework版本為ASP.NET 2.0 的方法 一

IIS 6.0以后使用MetaBase.xml存儲(chǔ)IIS信息,因此,可以直接修改這個(gè)文件即可。

代碼如下: 很顯然,這種方法比較復(fù)雜,不直觀,而且需要停止IIS,影響現(xiàn)有網(wǎng)站。

/// <summary>
/// 本方法創(chuàng)建一個(gè)站點(diǎn)(當(dāng)然,創(chuàng)建虛擬目錄也完全沒(méi)有任何問(wèn)題,做法類似),并設(shè)置IIS中ASP.NET版本為2.0
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//站點(diǎn)名稱和物理路徑
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;
//得到現(xiàn)有的站點(diǎn)標(biāo)識(shí)
foreach (DirectoryEntry entry in root.Children)
{
if (entry.SchemaClassName == "IIsWebServer")
{
int ID = Convert.ToInt32(entry.Name);

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

//利用配置文件的做法創(chuàng)建站點(diǎn),需要先停止原來(lái)的服務(wù),以便能夠順利寫入數(shù)據(jù)
label1.Text = "正在停止服務(wù)……";
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);
}
//確保服務(wù)完全停止
label1.Text = "停止服務(wù)完成!";
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");

//得到最大的網(wǎng)站的標(biāo)識(shí),要在其后面加入節(jié)點(diǎn)
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("沒(méi)有現(xiàn)有的 Web 服務(wù)器。");
doc = null;
return;
}

//找到AdminACL設(shè)置,每次都是變化的 -_-!
System.Xml.XmlNode LastWebServerFilter = doc.SelectSingleNode("/mxh:configuration/mxh:MBProperty/mxh:IIsFilters[@Location=\'" + SiteLocation + "/filters\']/@AdminACL", xnm);
if (LastWebServer == null)
{
MessageBox.Show("沒(méi)有現(xiàn)有的 Web 服務(wù)器 filters。");
doc = null;
return;
}

String LastWebServerFilterAdminAcl = LastWebServerFilter.Value;

//創(chuàng)建新站點(diǎn)
label1.Text = "創(chuàng)建新站點(diǎn)……";
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 = "默認(rèn)應(yīng)用程序";
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);

//關(guān)于權(quán)限,可以任意組合
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);

//為安全起見,下面的系統(tǒng)文件夾需要使用程序的方法獲取,如System.Environment.SystemDirectory,和System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
//這里為了簡(jiǎn)單期間,直接寫入
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 = "創(chuàng)建站點(diǎn)完成!";
mobServiceController3 = null;
mobServiceController3 = new System.ServiceProcess.ServiceController("w3svc");
mobServiceController3.Start();
mobServiceController3.WaitForStatus(ServiceControllerStatus.Running);
mobServiceController3 = null;
label1.Text = "恭喜你,全部工作完成!";
MessageBox.Show("恭喜你,全部工作完成!");
}

主站蜘蛛池模板: 亚洲高清一区二区三区 | 国产一区影视 | 欧美成人午夜在线全部免费 | 色射网| 国产精品久久久久久 | 一级黄色片aaa | 欧美不卡在线视频 | 毛片免费看网站 | 日韩视频在线观看 | 爱呦视频在线播放网址 | 男女性高清爱潮视频免费观看 | 成年人网站免费观看 | 一级国产精品一级国产精品片 | 久久成人18 | 男女午夜爱爱久久无遮挡 | 毛片搜索 | 亚洲影院手机版777点击进入影院 | 91视频国内| 久久五 | a毛片免费观看 | 精品一区二区三区五区六区 | 国产一极毛片 | 日韩精品在线观看免费 | 精品国产成a人在线观看 | 久久99亚洲精品久久久久 | 亚洲国产高清在线 | 一区二区不卡视频在线观看 | 三级免费网站 | 日韩一级片免费在线观看 | 娇小性色xxxxx中文 | 激情一区二区三区成人 | 岬奈一区二区中文字幕 | 91porny九色国产首页在线 | 色偷偷亚洲偷自拍 | 日韩欧美亚洲每的更新在线 | 一本色道久久爱88av | 成人满18在线观看网站免费 | 亚洲精品国产成人一区二区 | 一个人免费观看日本www视频 | baby在线观看免费观看 | 国产在线精品一区二区高清不卡 |