Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Display Photo from Acitve Directory Server?

$
0
0

Hi Folks,

I am using Asp.net Core with Angular 4 and Novell LDAP library acitve directory. I fellow this one as below:
https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard/blob/master/original_samples/Samples/Search.cs

I want to display thumbnail Photo from active directory. Here is in my code:

In C#:

public struct PersonEntry
{
	..............
	//Rest Omitted
	..............
    public byte[] ThumbnailPhoto { get; set; }
}

[HttpGet("testPhoto")]
public IActionResult Test()
{
	..............
	//Rest Omitted
	..............
    while (lsc.hasMore())
    {
        LdapEntry nextEntry = null;
        try
        {
            nextEntry = lsc.next();
        }
        catch (LdapException e)
        {
            Console.WriteLine("Error: " + e.LdapErrorMessage);
            // Exception is thrown, go for next entry
            continue;
        }

        var entry = new PersonEntry();

        LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
        IEnumerator ienum = attributeSet.GetEnumerator();

        while (ienum.MoveNext())
        {
            LdapAttribute attribute = (LdapAttribute)ienum.Current;
            string attributeName = attribute.Name;
            string attributeVal = attribute.StringValue;

            if (!Base64.isLDIFSafe(attributeVal))
            {
                byte[] tbyte = SupportClass.ToByteArray(attributeVal);
                attributeVal = Base64.encode(SupportClass.ToSByteArray(tbyte));
            }

            switch (attributeName)
            {
                case "sAMAccountName":
                    entry.UserName = attributeVal;
                    break;
                case "displayName":
                    entry.Name = attributeVal;
                    break;
                case "thumbnailPhoto":
                    entry.ThumbnailPhoto = Encoding.ASCII.GetBytes(attributeVal);
                    break;
                default:
                    break;
            }
        }
        attributeListObject.Add(entry);
    }
    conn.Disconnect();
    return Ok(attributeListObject);
	..............
	//Rest Omitted
	..............
}

In HTML:

<div *ngIf="imageData != ''"><p><b>From Active Directory:</b></p><img [src]="imageData" alt="test" /></div><div *ngIf="imageLocalData != ''"><p><b>From Local Database:</b></p><img [src]="imageLocalData" alt="test" /></div>

In Typescript:

    testPic() {
        this.appService.testPic().subscribe(data => {
            let byteData = 'data:image/jpeg;base64,' + data[0].thumbnailPhoto;this.imageData = this.sanitizer.bypassSecurityTrustResourceUrl(byteData);
        });

        this.appService.testAttachment(1).subscribe(data => {
            let byteData = 'data:image/jpeg;base64,' + data[0].data;this.imageLocalData = this.sanitizer.bypassSecurityTrustResourceUrl(byteData);
        });
    }


In second last picture (From Local database), I got display image byte. This byte is stored in local database as MSSQl after I uploaded it.
Unfortunatley, In first picture (From Actvie Directory), I am unable to display image byte as ThumbnailPhoto from Active directory server and I have no clue.
I was wondering if you can help this issue. Thanks in Advance.

I am waiting for your response.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>