从Active Directory中获取EmailAddress为NULL(AccountManagement UserPrincipal) [英] Getting EmailAddress NULL from Active Directory (AccountManagement UserPrincipal)

查看:153
本文介绍了从Active Directory中获取EmailAddress为NULL(AccountManagement UserPrincipal)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,找不到解决方法:

I have a problem and can not find solution:

我有下面的代码来检索正在访问Web应用程序的电子邮件(EmailAddress)用户.

I have the code below to retrieve the e-mail (EmailAddress) user that is accessing the web application.

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)带有空值.

For some users (so far three) the e-mail (EmailAddress) comes with a null value.

我也尝试了下面的代码,并且发生了同样的事情:

I also tried the code below and the same happens:

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有关,但由于缺乏知识我不能说.

I am suspicious that has something to do with Exchange Server, but I can not say for lack of knowledge.

任何人都可以帮忙吗?

推荐答案

系统托管在使用森林和域树的体系结构上.

The system is hosted on an architecture that uses forests and tree of domains.

已实现的代码访问其正在运行的上下文的AD.

The implemented code accesses the AD of context in which it is running.

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

In this case, the AD responsible for the context of the application was not updated. The users who have problems were not with the e-mail address filled this AD.

当咨询主广告时,使用了一些相关工具,信息就正确地存在了,从而引起了混乱.

And when it consulted the main AD, with some tool for this, the information was there correctly, which caused confusion.

经过一些调查发现混乱.

After some investigations was detected confusion.

就是这样.问题解决了!

That's it. Problem solved!

谢谢合作!

这篇关于从Active Directory中获取EmailAddress为NULL(AccountManagement UserPrincipal)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆