0

i am using the following code to get Extended property "JobCode"

    [DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("Person")]
public class UserPrincipalEx : UserPrincipal
{
    public static new UserPrincipalEx FindByIdentity(PrincipalContext context, string identityValue)
    {
        return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityValue);
    }

    // Implement the overloaded search method FindByIdentity. 
    public static new UserPrincipalEx FindByIdentity(PrincipalContext context, IdentityType identityType, string identityValue)
    {
        return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityType, identityValue);
    }
    // Inplement the constructor using the base class constructor. 
    public UserPrincipalEx(PrincipalContext context)
        : base(context)
    { }

    // Implement the constructor with initialization parameters.    
    public UserPrincipalEx(PrincipalContext context,
                         string samAccountName,
                         string password,
                         bool enabled)
        : base(context, samAccountName, password, enabled)
    { }

    // Create the "extensionAttribute2" property.    
    [DirectoryProperty("JobCode")]
    public string JobCode
    {
        get
        {
            if (ExtensionGet("JobCode").Length != 1)
                return string.Empty;

            return (string)ExtensionGet("JobCode")[0];
        }
        set { ExtensionSet("JobCode", value); }
    }
}

i can get the property when working locally using windows authentication.

        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;
    }

but this code cannot find the extended property "JobCode" when in production means when it is in deployed.

kindly help

Raas Masood
  • 1,475
  • 3
  • 23
  • 61

0 Answers0