/// 删除Web|Ftp虚拟目录
/// </summary>
/// <param name = "strVirDirName">
/// 欲删除虚拟目录的名称。
/// </param>
/// <returns>
/// 无返回值。<br/>
/// 如果欲删除的虚拟目录不存在,则抛出异常。注意在调用处捕获该异常。
/// </returns>
public void DeleteVirDir(string strVirDirName)
{
if(Exists(strVirDirName))
{
object[] VirDirParas = new object[2];
VirDirParas[0] = KeyType;
VirDirParas[1] = strVirDirName;
RootDE.Invoke("Delete", VirDirParas);
RootDE.CommitChanges();
}
else
{
throw new Exception("DeleteVirDir Exception:Virtual directory doesn't exist!");
}
}
/// <summary>
/// 更新Web|Ftp虚拟目录。
/// </summary>
/// <param name = "VD">
/// 更新虚拟目录时,将用属性集覆盖原有属性。
/// </param>
/// <returns>
/// 无返回值。<br/>
/// 如果欲更新的虚拟目录不存在,则抛出异常。注意在调用处捕获该异常。
/// </returns>
public void UpdateVirDir(VirtualDirectory VD)
{
DirectoryEntry de = GetVirDir(VD.Name);
if(de != null)
{
UpdateDirInfo(de, VD);
}
else
{
throw new Exception("UpdateVirDir Exception:The virtual directory doesn't exist!");
}
}
/// <summary>
/// 用属性集VD覆盖更新虚拟目录DE。<br/>
/// 当是UNC共享虚拟目录时,需要指定UNC虚拟账户。<br/>
/// Web虚拟目录的有些属性,Ftp虚拟目录并没有,
/// 分别设置Ftp和Web虚拟目录的属性。<br/>
/// </summary>
/// <param name = "DE">欲更新的虚拟目录入口</param>
/// <param name="VD">欲更新的属性集</param>
/// <returns>无返回值</returns>
public void UpdateDirInfo(DirectoryEntry DE, VirtualDirectory VD)
{
DE.Properties["Path"][0] = VD.Path;
// IISWebVirtualDir和IISFtpVirtualDir都有以下三个属性
DE.Properties["AccessRead"][0] = VD.AccessRead;
DE.Properties["AccessWrite"][0] = VD.AccessWrite;
DE.Properties["DontLog"][0] = VD.DontLog;
// 以下属性的修改只对IISWebVirtualDir有效!
if (DE.SchemaClassName == "IIsWebVirtualDir")
{
DE.Properties["AppFriendlyName"][0] = VD.AppFriendlyName;
DE.Properties["AccessExecute"][0] = VD.AccessExecute;
DE.Properties["AccessScript"][0] = VD.AccessScript;
DE.Properties["ContentIndexed"][0] = VD.ContentIndexed;
DE.Properties["EnableDirBrowsing"][0] = VD.EnableDirBrowsing;
DE.Properties["AppIsolated"][0] = VD.AppIsolated;
}
// 如果是UNC共享虚拟目录,则需要设置UNC账户
if (VD.IsUNCShare())
{
DE.Properties["UNCUserName"][0] = VD.UNCUsername;
DE.Properties["UNCPassword"][0] = VD.UNCPassword;
}
DE.CommitChanges();
}
}
}
评论