Starts in:
2 DAYS
5 HRS
47 MIN
18 SEC
Starts in:
2 D
5 H
47 M
18 S
Open Closed

Use new custom User field in razor page code #785


User avatar
0
chofoza created
  • ABP Framework version: v4.1.0
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Seperated (Angular): no

Hi, I feel like this is an easy one...

I have a new property (bool Active) on the User object, stored in ExtraProperties. I want to reference it on the razor page, but the CurrentUser (ICurrentUser) object doesn't have it or ExtraProperties. How can I read the value?

In my example basically I want to do:

@if (CurrentUser.IsAuthenticated && CurrentUser.ExtraProperties["Active"])


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    1. You can use UserManager in razor page to get user's Active . https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Security/Volo/Abp/Users/CurrentUserExtensions.cs#L15
    2. You can also add this value into the cliams.https://github.com/abpframework/abp/blob/dev/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpUserClaimsPrincipalFactory.cs#L29
  • User Avatar
    0
    chofoza created

    Thank you, it worked. I had tried to use the UserManager but obviously was too lazy to find its namespace so wasted a question instead!

    Thanks for your help.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06