1
我有一个问题,找不到解决办法:获得从Active Directory(AccountManagement UserPrincipal)EmailAddress的NULL
我有下面的代码来检索访问Web应用程序的电子邮件(EmailAddress
)用户。
var pc = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain);
var user = System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(pc, System.DirectoryServices.AccountManagement.IdentityType.SamAccountName, username.ToLower());
email = user.EmailAddress;
对于一些用户(迄今为止三)电子邮件(EmailAddress
)带有一个空值。
我也试过下面的代码和同样的情况:
string connection = "LDAP://name.org";
DirectoryEntry entry = new DirectoryEntry(connection);
DirectorySearcher dssearch = new DirectorySearcher(entry);
dssearch.Filter = "(sAMAccountName=UserLogin)";
SearchResult sresult = dssearch.FindOne();
DirectoryEntry dsresult = sresult.GetDirectoryEntry();
if (dsresult.Properties.Count > 0)
{
if (dsresult.Properties["mail"].Count > 0)
Response.Write("email: " + dsresult.Properties["mail"][0].ToString());
}
else
Response.Write("<p>não encontrou</p>");
我怀疑是不是有事情做与Exchange Server,但我不能因为缺乏知识的说。
任何人都可以帮忙吗?
所以最新的解决方案????? – 2013-10-09 17:09:06
更新应用程序运行环境的AD。 – 2015-10-21 14:12:51
我遇到了同样的问题。代码没有问题,AD数据库本身就是AD服务器本身。 – 2016-01-20 23:40:41