3,244
社区成员




DirectoryEntry entry = new DirectoryEntry("LDAP://域名",域内任一帐户名","password" );
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(cn=" + user.Name + "))"; //搜索适配器
mySearcher.PropertiesToLoad.Add("userPrincipalName");//添加自己需要找的属性
mySearcher.PropertiesToLoad.Add("department");
mySearcher.PropertiesToLoad.Add("mail");
mySearcher.PropertiesToLoad.Add("title");
var result = mySearcher.FindOne(); //找到自己需要的一个
System.Security.Principal.WindowsIdentity
验证用户是否为当前所登陆的用户。我的情况是iuser,即IISuser登陆,这个用户固然是不能访问域的。
那么 SPSecurity.RunWithElevatedPrivileges(delegate()
{})
切换为当前登陆sharepoint用户,若用户与web所在同一个域,且用户已经登陆网站的情况下,使用directortSearch访问域就不需要再次 输入用户名密码了。
关于 SPSecurity.RunWithElevatedPrivileges(delegate(){})我之前一直以为是提权限操作,提成超级用户。不想这次发现并不是我想的超级用户,而是变成了当前登录用户。关于这个函数后续我会再研究下在博客里记录一下~有懂得大神在这里指点小弟一二也可以~谢谢~