locked
Querying UserPrincipal for extensionattribute3 RRS feed

  • Question

  • User943380187 posted

    I am trying to query extended attributes through Active Directory UserPrincipal object. I have looked at examples of how to extend the attributes but am still unable to get the value of extensionattribute3 of the user retrieved with the following code. Any advice on how to retreive the extensionattribute3 value using VB.NET greatly appreciated.

     Using Hosting.HostingEnvironment.Impersonate()
    
                Using context = New PrincipalContext(ContextType.Domain, "DOMAIN.NAME", Nothing, ContextOptions.Negotiate)
    
                    Dim currentUser As UserPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, Environment.UserName)
    
                    Response.Write(currentUser.extensionattribute3)
    
    
    
    
                End Using
    
            End Using

    Monday, March 30, 2015 4:21 PM

Answers

  • User1508394307 posted

    I'd try

    DirectoryEntry de = (currentUser.GetUnderlyingObject() as DirectoryEntry);
    
    if (de != null)
    {
       if (de.Properties.Contains("extensionattribute3"))
       {
            string x = de.Properties["extensionattribute3"][0].ToString();
       }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 31, 2015 7:04 AM

All replies

  • User1508394307 posted

    I'd try

    DirectoryEntry de = (currentUser.GetUnderlyingObject() as DirectoryEntry);
    
    if (de != null)
    {
       if (de.Properties.Contains("extensionattribute3"))
       {
            string x = de.Properties["extensionattribute3"][0].ToString();
       }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 31, 2015 7:04 AM
  • User943380187 posted

    Thanks, that worked. My original problem was also impersonation was not working through out website, after specifying an account /password in the context I was able to use your provided code to get the property value,

    Thanks!

    Tuesday, March 31, 2015 11:42 AM