据我所知,有两个Active Directory属性:msIIS-FTPROOT,msIIS-FTPDir。
从Technet
基本上,用户的主文件夹验证时由查询msIIS-FTPROOT和msIIS-FTPDir确定在Active Directory用户对象的属性。 msIIS-FTPRoot和msIIS-FTPDir值的连接会生成用户主文件夹的路径。
一个例子可以是这样的:
msIIS-FTPRoot = D:\FTP Users
msIIS-FTPDir = \JohnSmith
这将导致 “d:\ FTP用户\ JohnSmith对” 作为用户的主文件夹。
代码遍历所有用户有默认目录:
static void Main(string[] args)
{
string domain = Environment.GetEnvironmentVariable("USERDNSDOMAIN");
string dc = GetDC(domain);
string ldap = String.Format("LDAP://{0}/{1}", domain, dc);
DirectoryEntry e = new DirectoryEntry(ldap);
DirectorySearcher src = new DirectorySearcher(e, "(objectClass=user)");
SearchResultCollection res = src.FindAll();
foreach (SearchResult r in res)
{
DirectoryEntry f = r.GetDirectoryEntry();
Console.WriteLine(f.Name + "\t" + f.Properties["msIIS-FTPRoot"].Value + f.Properties["msIIS-FTPDir"].Value);
}
Console.ReadKey();
}
private static string GetDC(string domain)
{
StringBuilder sb = new StringBuilder(domain);
sb.Replace(".", ",DC=");
sb.Insert(0, "DC=");
return sb.ToString();
}
这篇文章可以帮助(IIS7只): - [自动化IIS管理与C#(http://forums.iis.net/t /1150298.aspx)第二个回复中的代码。 – GrayWizardx 2010-01-06 05:26:18