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

Get data from active directory using react and asp.net core

$
0
0

Can someone share code to retrieve user details along with thumbnail image to be displayed basis the input SamAccountName. This has to be accomplished using asp.net core and react. I am pretty new to this technology, please help.

My trials till now:

Controller:
public Image ourTeam()
{
var userDetails = db.users.Where(x=>x.saMAccountName == "someUsername").FirstOrDefault();

Image image = GetImage(userDetails.CN); //I get image data
var stream = new System.IO.MemoryStream();

if (image != null)
image.Save(stream, ImageFormat.Jpeg);

return image;
}

Component
import * as React from 'react';
import { RouteComponentProps } from 'react-router';

interface FetchImageDataState {
imageList: ImageData[];
loading: boolean;
}

export class OurTeam extends React.Component<RouteComponentProps<{}>, FetchImageDataState> {
constructor() {
super();
this.state = { imageList: [], loading: true }; //initialize to default

fetch('api/Home/ourTeam')
.then(response => response.json() as Promise<ImageData[]>)
.then(data => {
this.setState({ imageList: data, loading: false });
});
}


public render() {

let contents = this.state.loading
? <p><em>Loading...</em></p>
: this.renderImageTable(this.state.imageList);
return <div>
<h1>Team</h1>{contents}
</div>;
}

private renderImageTable(imageList: ImageData[]) {
return <div className='table'>{
imageList.map(x =>
<img src={x.byteData} alt={x.CN} />)
}</div>;}
}

export class ImageData {
CN: string = "";
byteData: string = "";
}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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