简体   繁体   中英

thumbnailPhoto not getting in case of Global Catalog

I have created a AD forest that search for a user across all domains in the forest using its global catalog connection string.

I am trying to get thumbnailPhoto of AD user using c# code. But I did not get thumbnailPhoto property in result object even though it exist in AD.

I had verified the thumbnailPhoto prop in AD using powershell. Also I have verified it by getting using LDAP connection string. It both case I got the byte array.

Below is the code to get user and its properties and _configuration.GlobalCatalog returns the Global catalog connections string which is in format (GC://domain-name).

public Task<ProfileImage> GetProfileImageByEmail(string email)
{
    var filterQuery = ("mail=" + email);
    return Task.FromResult(GetProfileImageFromAD(filterQuery));
}

private ProfileImage GetProfileImageFromAD(string filterQuery)
{
    var result = GetADUserDetails(filterQuery);

    if (result == null)
        return null;

    if (result.Properties.Contains("thumbnailPhoto"))
    {
        var imageBytes = result.Properties["thumbnailPhoto"][0] as byte[];

        if (imageBytes != null)
        {
            return new ProfileImage
            {
                Content = new MemoryStream(imageBytes),
                ContentType = "image/jpeg"
            };
        }
    }

    return null;
}

private SearchResult GetADUserDetails(string filterQuery)
{
    using (var userBinding = new DirectoryEntry(_configuration.GlobalCatalog))
    {

        using (DirectorySearcher adSearch = new DirectorySearcher(userBinding))
        {
            adSearch.ReferralChasing = ReferralChasingOption.All;
            adSearch.Filter = filterQuery;
            adSearch.PropertiesToLoad.Add("mail");
            adSearch.PropertiesToLoad.Add("sn");
            adSearch.PropertiesToLoad.Add("givenName");
            adSearch.PropertiesToLoad.Add("thumbnailPhoto");

            return adSearch.FindOne();
        }
    }
}

Any help is appreciated.

Update: 在AD上运行LDP以获取用户详细信息

On a domain controller open ADSIEdit, connect to Schema Naming Context, find attribute CN=Picture,CN=Schema,CN=Configuration... and go to it's properties. Verify that isMemberOfPartialAttributeSet is set to TRUE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM