C# 无法获取Active Directory';它在生产中的延伸属性。

C# 无法获取Active Directory';它在生产中的延伸属性。,c#,active-directory,ldap-query,extended-properties,C#,Active Directory,Ldap Query,Extended Properties,我使用以下代码获取扩展属性“JobCode” 使用windows身份验证在本地工作时,我可以获取该属性 private string GetJobCode(string username) { string jobCode = String.Empty; using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain)) {

我使用以下代码获取扩展属性“JobCode”

使用windows身份验证在本地工作时,我可以获取该属性

        private string GetJobCode(string username)
    {
        string jobCode = String.Empty;
        using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
        {
            UserPrincipalEx inetPerson = UserPrincipalEx.FindByIdentity(ctx,  username);
            if (inetPerson != null)
            {
                jobCode = inetPerson.JobCode;
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(inetPerson.JobCode == String.Empty ? "no job code found" : "job code is " + jobCode));
            }
            else
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("JobCode property was not found"));
            }
        }
        return jobCode;
    }
但此代码在生产环境中找不到扩展属性“JobCode”,这意味着它在部署环境中


请帮忙

您是否登录了产品?你知道你是否在这一行上得到任何结果吗?是的,我可以在visual studio中看到字符串结果。如果没有jobCode,对于少数用户来说,如果没有jobCode,我只会在那一行得到空字符串inetPerson obj为空。但是对于用户,我检查他们是否有工作代码。只是在生产中返回空值。
        private string GetJobCode(string username)
    {
        string jobCode = String.Empty;
        using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
        {
            UserPrincipalEx inetPerson = UserPrincipalEx.FindByIdentity(ctx,  username);
            if (inetPerson != null)
            {
                jobCode = inetPerson.JobCode;
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(inetPerson.JobCode == String.Empty ? "no job code found" : "job code is " + jobCode));
            }
            else
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("JobCode property was not found"));
            }
        }
        return jobCode;
    }