using System;
using System.DirectoryServices;
using System.Collections;
namespace WayControls.IIS
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// IISWebServer的状态
/// </summary>
public enum IISServerState
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
Starting = 1,
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
Started = 2,
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
Stopping = 3,
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
Stopped = 4,
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
Pausing = 5,
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
Paused = 6,
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
Continuing = 7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// IISManagement 的摘要说明。
/// </summary>
public class IISManagement
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebServerCollection WebServers = new IISWebServerCollection();
internal static string Machinename = "localhost";
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISManagement()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
start();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="MachineName">机器名,默认值为localhost</param>
public IISManagement(string MachineName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( MachineName.ToString() != "" )
Machinename = MachineName;
start();
}
private void start()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry Service = new DirectoryEntry("IIS://" + Machinename + "/W3SVC");
DirectoryEntry Server;
DirectoryEntry Root = null;
DirectoryEntry VirDir;
IEnumerator ie = Service.Children.GetEnumerator();
IEnumerator ieRoot;
IISWebServer item;
IISWebVirtualDir item_virdir;
bool finded = false;
while(ie.MoveNext())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = (DirectoryEntry)ie.Current;
if( Server.SchemaClassName == "IIsWebServer" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
item = new IISWebServer();
item.index = Convert.ToInt32(Server.Name);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
item.ServerComment = (string)Server.Properties["ServerComment"][0];
item.AccessRead = (bool)Server.Properties["AccessRead"][0];
item.AccessScript = (bool)Server.Properties["AccessScript"][0];
item.DefaultDoc = (string)Server.Properties["DefaultDoc"][0];
item.EnableDefaultDoc = (bool)Server.Properties["EnableDefaultDoc"][0];
item.EnableDirBrowsing = (bool)Server.Properties["EnableDirBrowsing"][0];
ieRoot = Server.Children.GetEnumerator();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while( ieRoot.MoveNext() )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Root = (DirectoryEntry)ieRoot.Current;
if( Root.SchemaClassName == "IIsWebVirtualDir" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
finded = true;
break;
}
}
if( finded )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
item.Path = Root.Properties["path"][0].ToString();
}
item.Port = Convert.ToInt32( ((string)Server.Properties["Serverbindings"][0]).Substring(1 ,((string)Server.Properties["Serverbindings"][0]).Length - 2 ) );
this.WebServers.Add_(item);
ieRoot = Root.Children.GetEnumerator();
while( ieRoot.MoveNext() )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
VirDir = (DirectoryEntry)ieRoot.Current;
if( VirDir.SchemaClassName != "IIsWebVirtualDir" && VirDir.SchemaClassName != "IIsWebDirectory" )
continue;
item_virdir = new IISWebVirtualDir(item.ServerComment);
item_virdir.Name = VirDir.Name;
item_virdir.AccessRead = (bool)VirDir.Properties["AccessRead"][0];
item_virdir.AccessScript = (bool)VirDir.Properties["AccessScript"][0];
item_virdir.DefaultDoc = (string)VirDir.Properties["DefaultDoc"][0];
item_virdir.EnableDefaultDoc = (bool)VirDir.Properties["EnableDefaultDoc"][0];
if( VirDir.SchemaClassName == "IIsWebVirtualDir" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
item_virdir.Path = (string)VirDir.Properties["Path"][0];
}
else if( VirDir.SchemaClassName == "IIsWebDirectory" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
item_virdir.Path = Root.Properties["Path"][0] + "\" + VirDir.Name;
}
item.WebVirtualDirs.Add_(item_virdir);
}
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 创建站点
/// </summary>
/// <param name="iisServer"></param>
public static void CreateIISWebServer(IISWebServer iisServer)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( iisServer.ServerComment.ToString() == "" )
throw(new Exception("IISWebServer的ServerComment不能为空!"));
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server;
int i = 0 ;
IEnumerator ie = Service.Children.GetEnumerator();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while(ie.MoveNext())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = (DirectoryEntry)ie.Current;
if( Server.SchemaClassName == "IIsWebServer" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( Convert.ToInt32(Server.Name) > i )
i = Convert.ToInt32(Server.Name);
// if( Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":" )
// {
// Server.Invoke("stop",new object[0]);
// }
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
i++;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
iisServer.index = i;
Server = Service.Children.Add(i.ToString() , "IIsWebServer");
Server.Properties["ServerComment"][0] = iisServer.ServerComment;
Server.Properties["Serverbindings"].Add(":" + iisServer.Port + ":");
Server.Properties["AccessScript"][0] = iisServer.AccessScript;
Server.Properties["AccessRead"][0] = iisServer.AccessRead;
Server.Properties["EnableDirBrowsing"][0] = iisServer.EnableDirBrowsing;
Server.Properties["DefaultDoc"][0] = iisServer.DefaultDoc;
Server.Properties["EnableDefaultDoc"][0] = iisServer.EnableDefaultDoc;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
DirectoryEntry root = Server.Children.Add("Root","IIsWebVirtualDir");
root.Properties["path"][0] = iisServer.Path;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Service.CommitChanges();
Server.CommitChanges();
root.CommitChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
root.Invoke("AppCreate2" , new object[1]
{2});
//Server.Invoke("start",new object[0]);
}
catch(Exception es)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(es);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 删除IISWebServer
/// </summary>
public static void RemoveIISWebServer(string ServerComment)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server;
IEnumerator ie = Service.Children.GetEnumerator();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ServerComment = ServerComment.ToLower();
while(ie.MoveNext())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = (DirectoryEntry)ie.Current;
if( Server.SchemaClassName == "IIsWebServer" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( Server.Properties["ServerComment"][0].ToString().ToLower() == ServerComment )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Service.Children.Remove(Server);
Service.CommitChanges();
return ;
}
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 删除IISWebServer
/// </summary>
public static void RemoveIISWebServer(int index)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry Server = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
if( Server != null )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Service.Children.Remove(Server);
Service.CommitChanges();
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(new Exception("找不到此IISWebServer"));
}
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(new Exception("找不到此IISWebServer"));
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 检查是否存在IISWebServer
/// </summary>
/// <param name="ServerComment">网站说明</param>
/// <returns></returns>
public static bool ExistsIISWebServer(string ServerComment)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ServerComment = ServerComment.Trim();
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server = null;
IEnumerator ie = Service.Children.GetEnumerator();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
string comment;
while(ie.MoveNext())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = (DirectoryEntry)ie.Current;
if( Server.SchemaClassName == "IIsWebServer" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
comment = Server.Properties["ServerComment"][0].ToString().ToLower().Trim();
if( comment == ServerComment.ToLower() )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return false;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 返回指定的IISWebServer
/// </summary>
/// <param name="ServerComment"></param>
/// <returns></returns>
internal static DirectoryEntry returnIISWebserver(string ServerComment)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ServerComment = ServerComment.Trim();
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server = null;
IEnumerator ie = Service.Children.GetEnumerator();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
string comment;
while(ie.MoveNext())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = (DirectoryEntry)ie.Current;
if( Server.SchemaClassName == "IIsWebServer" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
comment = Server.Properties["ServerComment"][0].ToString().ToLower().Trim();
if( comment == ServerComment.ToLower() )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return Server;
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return null;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 返回指定的IISWebServer
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
internal static DirectoryEntry returnIISWebserver(int index)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry Server = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IEnumerator ie = Server.Children.GetEnumerator();
return Server;
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return null;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private static DirectoryEntry getRoot( DirectoryEntry Server )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
foreach( DirectoryEntry child in Server.Children )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string name = child.Name.ToLower();
if( name == "iiswebvirtualdir" || name == "root" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return child;
}
}
return null;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 修改与给定的IISWebServer具有相同网站说明的站点配置
/// </summary>
/// <param name="iisServer">给定的IISWebServer</param>
public static void EditIISWebServer(IISWebServer iisServer)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( iisServer.index == -1 )
throw(new Exception("找不到给定的站点!"));
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
IEnumerator ie = Service.Children.GetEnumerator();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while(ie.MoveNext())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = (DirectoryEntry)ie.Current;
if( Server.SchemaClassName == "IIsWebServer" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server.Invoke("stop",new object[0]);
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Server = returnIISWebserver(iisServer.index);
if( Server == null )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw( new Exception("找不到给定的站点!"));
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Server.Properties["ServerComment"][0] = iisServer.ServerComment;
Server.Properties["Serverbindings"][0] = ":" + iisServer.Port + ":";
Server.Properties["AccessScript"][0] = iisServer.AccessScript;
Server.Properties["AccessRead"][0] = iisServer.AccessRead;
Server.Properties["EnableDirBrowsing"][0] = iisServer.EnableDirBrowsing;
Server.Properties["DefaultDoc"][0] = iisServer.DefaultDoc;
Server.Properties["EnableDefaultDoc"][0] = iisServer.EnableDefaultDoc;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
DirectoryEntry root = getRoot( Server );
Server.CommitChanges();
if( root != null )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
root.Properties["path"][0] = iisServer.Path;
root.CommitChanges();
}
Server.Invoke("start",new object[0]);
}
catch(Exception es)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(es);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 返回所有站点的网站说明
/// </summary>
/// <returns></returns>
public static ArrayList returnIISServerComment()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ArrayList list = new ArrayList();
IEnumerator ie = Service.Children.GetEnumerator();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while(ie.MoveNext())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = (DirectoryEntry)ie.Current;
if( Server.SchemaClassName == "IIsWebServer" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
list.Add(Server.Properties["ServerComment"][0]);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return list;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 创建虚拟目录
/// </summary>
/// <param name="iisVir"></param>
/// <param name="deleteIfExist"></param>
public static void CreateIISWebVirtualDir(IISWebVirtualDir iisVir , bool deleteIfExist)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( iisVir.Parent == null )
throw(new Exception("IISWebVirtualDir没有所属的IISWebServer!"));
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server = returnIISWebserver(iisVir.Parent.index);
if( Server == null )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw( new Exception("找不到给定的站点!"));
}
Server = getRoot( Server );
if( deleteIfExist )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
foreach( DirectoryEntry VirDir in Server.Children )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( VirDir.Name.ToLower().Trim() == iisVir.Name.ToLower() )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server.Children.Remove(VirDir);
Server.CommitChanges();
break;
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry vir;
vir = Server.Children.Add(iisVir.Name , "IIsWebVirtualDir");
vir.Properties["Path"][0] = iisVir.Path;
vir.Properties["DefaultDoc"][0] = iisVir.DefaultDoc;
vir.Properties["EnableDefaultDoc"][0] = iisVir.EnableDefaultDoc;
vir.Properties["AccessScript"][0] = iisVir.AccessScript;
vir.Properties["AccessRead"][0] = iisVir.AccessRead;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
vir.Invoke("AppCreate2" , new object[1]
{2});
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Server.CommitChanges();
vir.CommitChanges();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
catch(Exception es)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(es);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 删除虚拟目录
/// </summary>
/// <param name="WebServerComment">站点说明</param>
/// <param name="VirtualDir">虚拟目录名称</param>
public static void RemoveIISWebVirtualDir(string WebServerComment, string VirtualDir)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
VirtualDir = VirtualDir.ToLower();
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server = returnIISWebserver(WebServerComment);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (Server == null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw (new Exception("找不到给定的站点!"));
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Server = getRoot(Server);
foreach (DirectoryEntry VirDir in Server.Children)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (VirDir.Name.ToLower().Trim() == VirtualDir)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server.Children.Remove(VirDir);
Server.CommitChanges();
return;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
throw (new Exception("找不到给定的虚拟目录!"));
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 删除虚拟目录
/// </summary>
/// <param name="iisVir"></param>
public static void RemoveIISWebVirtualDir(IISWebVirtualDir iisVir)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server = returnIISWebserver(iisVir.Parent.index);
if( Server == null )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(new Exception( "找不到给定的站点!"));
}
Server = getRoot( Server );
foreach( DirectoryEntry VirDir in Server.Children )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( VirDir.Name.ToLower().Trim() == iisVir.Name.ToLower() )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server.Children.Remove(VirDir);
Server.CommitChanges();
return;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
throw(new Exception( "找不到给定的虚拟目录!"));
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public class IISWebServerCollection:CollectionBase
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebServer this[int Index]
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return (IISWebServer)this.List[Index];
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebServer this[string ServerComment]
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ServerComment = ServerComment.ToLower().Trim();
IISWebServer list;
for(int i = 0 ; i < this.List.Count ; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
list = (IISWebServer)this.List[i];
if(list.ServerComment.ToLower().Trim() == ServerComment)
return list;
}
return null;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
internal void Add_(IISWebServer WebServer)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.List.Add(WebServer);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="WebServer"></param>
public void Add(IISWebServer WebServer)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.List.Add(WebServer);
IISManagement.CreateIISWebServer(WebServer);
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 是否包含指定的网站
/// </summary>
/// <param name="ServerComment"></param>
/// <returns></returns>
public bool Contains(string ServerComment)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ServerComment = ServerComment.ToLower().Trim();
for( int i = 0 ; i < this.List.Count ; i++ )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IISWebServer server = this[i];
if( server.ServerComment.ToLower().Trim() == ServerComment )
return true;
}
return false;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 是否包含指定的网站
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public bool Contains(int index)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for( int i = 0 ; i < this.List.Count ; i++ )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IISWebServer server = this[i];
if( server.index == index )
return true;
}
return false;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="WebServers"></param>
public void AddRange(IISWebServer [] WebServers)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int i = 0 ; i <= WebServers.GetUpperBound(0) ; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Add(WebServers[i]);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="WebServer"></param>
public void Remove(IISWebServer WebServer)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int i=0;i<this.List.Count;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if((IISWebServer)this.List[i] == WebServer)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.List.RemoveAt(i);
return;
}
}
IISManagement.RemoveIISWebServer(WebServer.index);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**///////////////////
/// <summary>
///
/// </summary>
public class IISWebServer
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
internal int index = -1;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebVirtualDirCollection WebVirtualDirs ;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 网站说明
/// </summary>
public string ServerComment = "Way";
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 脚本支持
/// </summary>
public bool AccessScript = true;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 读取
/// </summary>
public bool AccessRead = true;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 物理路径
/// </summary>
public string Path = "c:\";
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 端口
/// </summary>
public int Port = 80;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 目录浏览
/// </summary>
public bool EnableDirBrowsing = false;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 默认文档
/// </summary>
public string DefaultDoc = "index.aspx";
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 使用默认文档
/// </summary>
public bool EnableDefaultDoc =true;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// IISWebServer的状态
/// </summary>
public IISServerState ServerState
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry server = IISManagement.returnIISWebserver(this.index);
if( server == null )
throw(new Exception("找不到此IISWebServer"));
switch (server.Properties["ServerState"][0].ToString())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
case "2":
return IISServerState.Started;
case "4":
return IISServerState.Stopped;
case "6":
return IISServerState.Paused;
}
return IISServerState.Stopped;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 停止IISWebServer
/// </summary>
public void Stop()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DirectoryEntry Server;
if( index == -1 )
throw(new Exception("在IIS找不到此IISWebServer!"));
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
if( Server != null )
Server.Invoke("stop" , new object[0]);
else
throw(new Exception("在IIS找不到此IISWebServer!"));
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(new Exception("在IIS找不到此IISWebServer!"));
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 把基本信息的更改更新到IIS
/// </summary>
public void CommitChanges()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IISManagement.EditIISWebServer(this);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 启动IISWebServer
/// </summary>
public void Start()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( index == -1 )
throw(new Exception("在IIS找不到此IISWebServer!"));
DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
DirectoryEntry Server;
IEnumerator ie = Service.Children.GetEnumerator();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while(ie.MoveNext())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = (DirectoryEntry)ie.Current;
if( Server.SchemaClassName == "IIsWebServer" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( Server.Properties["Serverbindings"][0].ToString() == ":" + this.Port + ":" )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server.Invoke("stop",new object[0]);
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Server = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
if( Server != null )
Server.Invoke("start" , new object[0]);
else
throw(new Exception("在IIS找不到此IISWebServer!"));
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(new Exception("在IIS找不到此IISWebServer!"));
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebServer()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
WebVirtualDirs = new IISWebVirtualDirCollection(this);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**////////////////////////////////////////////
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public class IISWebVirtualDirCollection:CollectionBase
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebServer Parent = null;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebVirtualDir this[int Index]
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return (IISWebVirtualDir)this.List[Index];
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebVirtualDir this[string Name]
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Name = Name.ToLower();
IISWebVirtualDir list;
for(int i = 0 ; i < this.List.Count ; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
list = (IISWebVirtualDir)this.List[i];
if(list.Name.ToLower() == Name)
return list;
}
return null;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
internal void Add_(IISWebVirtualDir WebVirtualDir)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.List.Add(WebVirtualDir);
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="WebVirtualDir"></param>
public void Add(IISWebVirtualDir WebVirtualDir)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
WebVirtualDir.Parent = this.Parent;
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.List.Add(WebVirtualDir);
}
catch
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw(new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
}
IISManagement.CreateIISWebVirtualDir(WebVirtualDir , true);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="WebVirtualDirs"></param>
public void AddRange(IISWebVirtualDir [] WebVirtualDirs)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int i = 0 ; i <= WebVirtualDirs.GetUpperBound(0) ; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Add(WebVirtualDirs[i]);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="WebVirtualDir"></param>
public void Remove(IISWebVirtualDir WebVirtualDir)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int i=0;i<this.List.Count;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if((IISWebVirtualDir)this.List[i] == WebVirtualDir)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.List.RemoveAt(i);
IISManagement.RemoveIISWebVirtualDir(WebVirtualDir);
return;
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="Parent"></param>
public IISWebVirtualDirCollection(IISWebServer Parent)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.Parent = Parent;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**////////////////
/// <summary>
///
/// </summary>
public class IISWebVirtualDir
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebServer Parent = null;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 虚拟目录名称
/// </summary>
public string Name = "Way";
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 读取
/// </summary>
public bool AccessRead = true;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 脚本支持
/// </summary>
public bool AccessScript = true;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 物理路径
/// </summary>
public string Path = "c:\";
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 默认文档
/// </summary>
public string DefaultDoc = "index.aspx";
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 使用默认文档
/// </summary>
public bool EnableDefaultDoc =true;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 所属的网站的网站说明
/// </summary>
public string WebServer = "";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
/// <param name="WebServerName"></param>
public IISWebVirtualDir(string WebServerName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( WebServerName.ToString() == "" )
throw(new Exception("WebServerName不能为空!"));
this.WebServer = WebServerName;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
///
/// </summary>
public IISWebVirtualDir()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
}
//添加新站点
IISManagement iisMan = new IISManagement("localhost");
IISWebServer IISserver;
IISserver = new IISWebServer();
IISserver.ServerComment = "我的站点";
IISserver.Path = "d:\webSites\test";
IISserver.EnableDefaultDoc = true;
IISserver.DefaultDoc = "myIndex.aspx";
iisMan.WebServers.Add(IISserver);
//添加虚拟目录
IISWebVirtualDir virDir_ = new IISWebVirtualDir();
virDir_.Path = "d:\mytest";
virDir_.Name = "新的虚拟目录名称";
virDir_.DefaultDoc = "default.aspx";
IISserver.WebVirtualDirs.Add(virDir_);