引用命名空间:
using System.DirectoryServices;
要实例的对象:
private Aspcn.Management.IISManager IISMan;
获取虚拟目录的物理路径
//获取虚拟路径的相关信息
private void btnGet_Click(object sender, System.EventArgs e)
{
tbServer.Text = "localhost";
tbWebSite.Text = "www.163.com";
tbVirDirName.Text = "DirectoryName";
string strVirdir = this.tbVirDirName.Text;
string strServer = this.tbServer.Text;
string strWebSite = this.tbWebSite.Text;
string strMsg = "";
try
{
IISMan.Connect(strServer,strWebSite);
VirtualDirectory vd = IISMan.GetVirDir(strVirdir);
this.tbVirDirName.Text = vd.Name;
this.tbPath.Text = vd.Path;
this.CBExecute.Checked = vd.AccessExecute;
this.CBRead.Checked = vd.AccessExecute;
this.CBScript.Checked = vd.AccessScript;
this.CBSSL.Checked = vd.AccessSSL;
this.CBWrite.Checked = vd.AccessWrite;
this.CBBasicAuth.Checked = vd.AuthBasic;
this.CBNtlmAuth.Checked = vd.AuthNTLM;
this.CBEnableIndexed.Checked = vd.ContentIndexed;
this.CBEnableDefaultDoc.Checked = vd.EnableDefaultDoc;
this.CBEnableBrowing.Checked = vd.EnableDirBrowsing;
this.tbPath.Text = vd.Path;
string[] defaultdoc = vd.DefaultDoc.Split(",".ToCharArray());
foreach(string item in defaultdoc)
{
if(item !="")
{
this.lstDefaultDoc.Items.Add(item);
}
}
strMsg = "获取" + strVirdir + "成功";
}
catch(Exception ee)
{
strMsg = "获取虚拟目录失败!错误如下:\n" + ee.ToString();
}
finally
{
MessageBox.Show(strMsg,"查看信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
//得到一个虚拟目录
public VirtualDirectory GetVirDir(string strVirdir)
{
VirtualDirectory tmp = null;
if(_virdirs.Contains(strVirdir))
{
tmp = _virdirs.Find(strVirdir);
((VirtualDirectory)_virdirs[strVirdir]).flag = 2;
}
else
{
throw new Exception("This virtual directory is not exists");
}
return tmp;
}
//获取虚拟路径的相关信息
private void btnGet_Click(object sender, System.EventArgs e)
{
tbServer.Text = "localhost";
tbWebSite.Text = "www.163.com";
tbVirDirName.Text = "DirectoryName";
string strVirdir = this.tbVirDirName.Text;
string strServer = this.tbServer.Text;
string strWebSite = this.tbWebSite.Text;
string strMsg = "";
try
{
IISMan.Connect(strServer,strWebSite);
VirtualDirectory vd = IISMan.GetVirDir(strVirdir);
this.tbVirDirName.Text = vd.Name;
this.tbPath.Text = vd.Path;
this.CBExecute.Checked = vd.AccessExecute;
this.CBRead.Checked = vd.AccessExecute;
this.CBScript.Checked = vd.AccessScript;
this.CBSSL.Checked = vd.AccessSSL;
this.CBWrite.Checked = vd.AccessWrite;
this.CBBasicAuth.Checked = vd.AuthBasic;
this.CBNtlmAuth.Checked = vd.AuthNTLM;
this.CBEnableIndexed.Checked = vd.ContentIndexed;
this.CBEnableDefaultDoc.Checked = vd.EnableDefaultDoc;
this.CBEnableBrowing.Checked = vd.EnableDirBrowsing;
this.tbPath.Text = vd.Path;
string[] defaultdoc = vd.DefaultDoc.Split(",".ToCharArray());
foreach(string item in defaultdoc)
{
if(item !="")
{
this.lstDefaultDoc.Items.Add(item);
}
}
strMsg = "获取" + strVirdir + "成功";
}
catch(Exception ee)
{
strMsg = "获取虚拟目录失败!错误如下:\n" + ee.ToString();
}
finally
{
MessageBox.Show(strMsg,"查看信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
//得到一个虚拟目录
public VirtualDirectory GetVirDir(string strVirdir)
{
VirtualDirectory tmp = null;
if(_virdirs.Contains(strVirdir))
{
tmp = _virdirs.Find(strVirdir);
((VirtualDirectory)_virdirs[strVirdir]).flag = 2;
}
else
{
throw new Exception("This virtual directory is not exists");
}
return tmp;
}