关闭

转孟老师有关创建站点并设置2.0的方法

1366人阅读 评论(0) 收藏 举报

转孟老师有关创建站点并设置2.0的方法

http://blog.csdn.net/net_lover/archive/2007/08/26/1759877.aspx

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

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

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

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 + @"inetsrvMetaBase.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:WINDOWSsystem32inetsrvasp.dll,5,GET,HEAD,POST,TRACE
                .cer,C:WINDOWSsystem32inetsrvasp.dll,5,GET,HEAD,POST,TRACE
                .cdx,C:WINDOWSsystem32inetsrvasp.dll,5,GET,HEAD,POST,TRACE
                .asa,C:WINDOWSsystem32inetsrvasp.dll,5,GET,HEAD,POST,TRACE
                .idc,C:WINDOWSsystem32inetsrvhttpodbc.dll,5,GET,POST
                .shtm,C:WINDOWSsystem32inetsrvssinc.dll,5,GET,POST
                .shtml,C:WINDOWSsystem32inetsrvssinc.dll,5,GET,POST
                .stm,C:WINDOWSsystem32inetsrvssinc.dll,5,GET,POST
                .asax,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ascx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ashx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .asmx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .aspx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .axd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .vsdisco,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .rem,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .soap,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .config,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .cs,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .csproj,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .vb,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .vbproj,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .webinfo,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .licx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .resx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .resources,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .xoml,C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .rules,C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .master,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .skin,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .compiled,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .browser,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .mdb,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .jsl,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .vjsproj,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .sitemap,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .msgx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .ad,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .dd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ldd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .sd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .cd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .adprototype,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .lddprototype,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .sdm,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .sdmDocument,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ldb,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .svc,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
                .mdf,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .ldf,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .java,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .exclude,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
                .refresh,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_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(
"恭喜你,全部工作完成!");
}

 

 

 

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

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

本方法代码如下:

string ScriptMaps = @".asp,C:WINDOWSsystem32inetsrvasp.dll,5,GET,HEAD,POST,TRACE
        .cer,C:WINDOWSsystem32inetsrvasp.dll,5,GET,HEAD,POST,TRACE
        .cdx,C:WINDOWSsystem32inetsrvasp.dll,5,GET,HEAD,POST,TRACE
        .asa,C:WINDOWSsystem32inetsrvasp.dll,5,GET,HEAD,POST,TRACE
        .idc,C:WINDOWSsystem32inetsrvhttpodbc.dll,5,GET,POST
        .shtm,C:WINDOWSsystem32inetsrvssinc.dll,5,GET,POST
        .shtml,C:WINDOWSsystem32inetsrvssinc.dll,5,GET,POST
        .stm,C:WINDOWSsystem32inetsrvssinc.dll,5,GET,POST
        .asax,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .ascx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .ashx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .asmx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .aspx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .axd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .vsdisco,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .rem,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .soap,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .config,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .cs,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .csproj,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .vb,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .vbproj,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .webinfo,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .licx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .resx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .resources,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .xoml,C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .rules,C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .master,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .skin,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .compiled,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .browser,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .mdb,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .jsl,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .vjsproj,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .sitemap,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .msgx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .ad,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .dd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .ldd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .sd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .cd,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .adprototype,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .lddprototype,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .sdm,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .sdmDocument,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .ldb,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .svc,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
        .mdf,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .ldf,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .java,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .exclude,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
        .refresh,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
";

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


///注意:这里没有进行进行端口存在的检查
// 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:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".asax,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".svc,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".msgx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".config,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG");
//ScriptMapsList.Add(@".ascx,c:windowsmicrosoft.net rameworkv2.0.50727aspnet_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(
"创建完成!");
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1101437次
    • 积分:13131
    • 等级:
    • 排名:第1075名
    • 原创:221篇
    • 转载:178篇
    • 译文:1篇
    • 评论:327条
    最新评论