开发者

LDAP using UserPrincipal missing a few fields in ActiveDirectory

I am accessing the Active Directory to fetch the employee Id from the Directory Server from my ASP.Net MVC account using the below code.

I am able to get the Given Name,SurName and voice t开发者_高级运维elephone number but not the Employee ID.But I know for sure that it is there.

I am developing in one machine and deploying in another so can I by some means authenticate from the code to the active directory and get the employee Id.what is the way to go about it?? Any HELP appreciated.

PrincipalContext context = new PrincipalContext(ContextType.Domain);
        UserPrincipal foundUser = UserPrincipal.FindByIdentity(context, "username");
        string employeeId = foundUser.EmployeeId;


The reason was because the active directory had the "employeeId" as a properties attribute.


Fyi, you could access these properties as follows:

PrincipalContext context = new PrincipalContext(ContextType.Domain);
UserPrincipal foundUser = UserPrincipal.FindByIdentity(context, "username");

PropertyCollection properties = (foundUser.GetUnderlyingObject() as DirectoryEntry).Properties;

foreach (PropertyValueCollection property in properties)
{
    if (property.PropertyName == "EmployeeId")
    {
        var id = property.Value;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜