【问题标题】:Getting EmailAddress NULL from Active Directory (AccountManagement UserPrincipal)从 Active Directory 获取 EmailAddress NULL (AccountManagement UserPrincipal)
【发布时间】:2013-03-26 17:49:44
【问题描述】:

我有一个问题,找不到解决方案:

我有下面的代码来检索正在访问 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 有关,但我不能说缺乏知识。

谁能帮忙?

【问题讨论】:

    标签: active-directory null account-management email-address userprincipal


    【解决方案1】:

    系统托管在使用森林和域树的架构上。

    实现的代码访问它正在运行的上下文的 AD。

    在这种情况下,负责应用程序上下文的 AD 未更新。有问题的用户不是填写此广告的电子邮件地址。

    当它使用一些工具咨询主要 AD 时,信息是正确的,这引起了混乱。

    经过一番调查发现混乱。

    就是这样。问题解决了!

    感谢合作!

    【讨论】:

    • 更新应用程序运行环境的 AD。
    • 我遇到了同样的问题。代码没有问题,是 AD 服务器本身有坏数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多