【发布时间】:2013-04-03 20:11:59
【问题描述】:
这是我正在尝试使用的代码,但我并没有真正使用它:
public static string GetUserIdFromEmail(string emailAddress)
{
string displayName = string.Empty;
if (emailAddress.Contains("@sub.domain.edu") || emailAddress.Contains("@domain.edu"))
{
displayName = emailAddress.Split(new char[] { '@' })[0];
}
else
{
//no active directory account.
return string.Empty;
}
// set up domain context
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
// find user by display name
try
{
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, displayName);
if (user != null)
{
return user.SamAccountName; // or UserPrincipleName
}
else
{
return string.Empty;
}
}
catch (Exception)
{
return "Error";
}
}
}
以下是我对我们当前系统的了解:
电子邮件将是独一无二的并遵循特定的命名约定
命名约定是名字的首字母和全名 (dstanley)。
Exchange 上的一些旧帐户是 first.last@email.com
我不知道自己在做什么,但我知道自己想要什么。
我希望能够获取用户域的电子邮件地址并在活动目录中找到他们的记录。上面的代码是在正确的轨道上还是我可以做一些更简单的事情?
【问题讨论】:
-
就个人而言,我喜欢承认 4 号的勇气。
-
哈,胆子?更像是“如果这是一个愚蠢的问题,请不要向我扔石头”之类的声明。我只是从未真正使用过 Intranet 应用程序,并尝试以编程方式获取 AD 内容。
-
在我们的行业中,人们常常没有意识到承认自己不知道自己在做什么是完全可以的。这就是这个网站存在的原因之一。
标签: c# active-directory exchange-server