User menu

Configure the signed-in user's details and menu at the bottom of the sidebar

When a user is logged in, the footer of the sidebar displays their avatar, name and email address. Clicking these opens the user menu, with a Log out menu item.

The bottom of the sidebar with the user's avatar, name and email address, and the user menu open with Log out

The user menu will not be visible to users who aren't logged in.

Specifying the user's details

StellarAdmin reads the user's details from their claims. You can specify different user claims using ConfigureUserMenu(). The example below displays the user's roles under their name, instead of their email address:

using System.Security.Claims;

admin.ConfigureUserMenu(menu => menu.DescriptionClaimType = ClaimTypes.Role);

The menu builder has the following members:

MemberDescription
NameClaimTypeSets the claim displayed as the user's name. The default is User.Identity.Name, or else the ClaimTypes.Name or name claim.
DescriptionClaimTypeSets the claim displayed under the name. When the user has several of these claims, such as a role claim for each role, StellarAdmin displays them all, such as "Sales, Finance". The default is the ClaimTypes.Email or email claim.
AvatarClaimTypeSets the claim with the URL of the user's picture. The default is picture. Without a picture, the avatar displays the user's initials.

When the user has no name, StellarAdmin displays their DescriptionClaimType claim, such as their email address, in place of the name.

Adding items to the menu

You can add your own items to the user menu by calling Add() on the user menu builder. The example below adds a link to the account page of ASP.NET Core Identity, with a separator between it and Log out:

using StellarAdmin.Sidebar;

admin.ConfigureUserMenu(menu =>
{
    menu.Add(UserMenuItem.Page("Account", "/Account/Manage/Index", "Identity", item =>
        item.Icon = "badge-check"));
    menu.Add(UserMenuItem.Separator());
});
The user menu with an Account item, a line, and Log out

The parameter passed to Add() can be one of the following:

ItemDescription
UserMenuItem.Url(text, url)A link to an absolute URL, or a path in your app that starts with ~/.
UserMenuItem.Page(text, page)A link to a Razor Page. To link to a page in an area, pass the area as well: Page(text, page, area).
UserMenuItem.Action(text, action, controller)A link to an MVC action. To link to an action in an area, pass the area as well: Action(text, action, controller, area).
UserMenuItem.Separator()A line between groups of items.

To display an icon before a link's text, pass a callback that sets Icon, as in the example above.

StellarAdmin displays the items in the order you add them, and Log out always appears last. To remove the items you added, call Clear(). It does not remove the Log out option.

Configuring log out

The Log out item posts to StellarAdmin's own logout endpoint, which signs the user out of the default authentication scheme and then opens the admin panel's home page. This works with cookie authentication and ASP.NET Core Identity.

Signing out of several schemes

When your app signs people in with more than one scheme, such as a cookie and OpenID Connect, call AddAuthenticationScheme() for each one, in the order StellarAdmin signs out of them. Add the local schemes, such as cookies, first, and the remote scheme last, because it may redirect to the identity provider:

admin.ConfigureUserMenu(menu => menu.Logout(logout =>
{
    logout.AddAuthenticationScheme(CookieAuthenticationDefaults.AuthenticationScheme);
    logout.AddAuthenticationScheme(OpenIdConnectDefaults.AuthenticationScheme);
    logout.RedirectPath = "~/";
}));

RedirectPath sets the page that opens after the user is signed out. A remote scheme, such as OpenID Connect, returns to this page from the identity provider. The default is the admin panel's home page.

Using your app's logout endpoint

To sign out with your app's own logout endpoint, such as the one in ASP.NET Core Identity, set Path. Log out then posts to that endpoint, with an antiforgery token, and the endpoint decides which page opens afterwards:

admin.ConfigureUserMenu(menu => menu.Logout(logout => logout.Path = "~/Identity/Account/Logout"));

StellarAdmin will always do an HTTP POST to the logout endpoint. If your logout endpoint uses a GET request, hide Log out and add a normal link to the endpoint:

admin.ConfigureUserMenu(menu =>
{
    menu.Logout(logout => logout.Show = false);
    menu.Add(UserMenuItem.Url("Log out", "~/logout"));
});

The logout builder has the following members:

MemberDescription
ShowSets whether the user menu displays Log out. The default is true.
IconSets the name of the icon displayed before Log out. The default is log-out.
PathSets your app's logout endpoint, as a path that starts with ~/. The default is null, which uses StellarAdmin's logout endpoint.
RedirectPathSets the page that opens after StellarAdmin's logout endpoint signs the user out. The default is the admin panel's home page.

Replacing the user menu

You can replace the user menu entirely by replacing the template by adding your own Areas/StellarAdmin/Views/Shared/_SidebarUserMenu.cshtml to your app. The view's model is a SidebarUserMenuModel, with the user's Name, Description and AvatarUrl, the menu's Items, and the Logout item. The folder needs the view imports.

On this page