的S.DS.AM命名空间是在.NET 3.5中引入的,不幸的是,它没有2.0版本。
您可以查询使用WindowsIdentity.GetCurrent当前的Windows用户在一个ASP.NET应用程序()名称 - 这给你域\用户名。
然后,你必须做一个用户搜索在AD与一个DirectorySearcher对象是用户,以便找到相应的DirectoryEntry。这将为您提供该用户的所有零碎信息。
string currentUser = WindowsIdentity.GetCurrent().Name;
string[] domainUserName = currentUser.Split('\\');
string justUserName = domainUserName[1];
DirectoryEntry searchRoot = new DirectoryEntry("LDAP://dc=(yourcompany),dc=com");
DirectorySearcher ds = new DirectorySearcher(searchRoot);
ds.SearchScope = SearchScope.Subtree;
ds.PropertiesToLoad.Add("sn");
ds.PropertiesToLoad.Add("givenName");
ds.Filter = string.Format("(&(objectCategory=person)(samAccountName={0}))", justUserName);
SearchResult sr = ds.FindOne();
if (sr != null)
{
string firstName = sr.Properties["givenName"][0].ToString();
string lastName = sr.Properties["sn"][0].ToString();
}
这是一个有点复杂,涉及.NET 2.0 - 不能改变这种:-(
马克
市建局天才......它的工作完美千恩万谢 – waqasahmed 2009-05-29 10:33:20