Skip to content

User Personalisation

Tom Longhurst edited this page Nov 25, 2021 · 2 revisions

If you create a class that implements the IUserPersonalizer, you can personalise the page with a name / profile picture, and links for that user.

An example is below. This is working in conjunction with the Microsoft AAD authentication to get the authenticated user's details.

    public class UserPersonaliser : IUserPersonalizer
    {
        public Uri? GetProfilePictureUri(HttpContext httpContext)
        {
            return null;
        }

        public string? GetNameOfUser(HttpContext httpContext)
        {
            return httpContext.User.FindFirst("name")?.Value;
        }

        public List<CustomLinkData> GetLinksForUser(HttpContext httpContext)
        {
            return new List<CustomLinkData>
            {
                new("My Account", new Uri("https://myaccount.microsoft.com/"))
            };
        }
    }

And in startup, make sure to add:

app.UseBDTestReportServer(options =>
{
    ...
    options.UserPersonalizer = new UserPersonaliser();
    ...
});
Clone this wiki locally