Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to get customize session values #6666


User avatar
0
kalidarscope created

i added UserClaimsPrincipalFactory.cs page

public override async Task<ClaimsPrincipal> CreateAsync(User user)
        {
            var claim = await base.CreateAsync(user);

            claim.Identities.First().AddClaim(new Claim("EmailAddress", user.EmailAddress));
           
            return claim;
        }

then Application.core page

    public ASAPSessions11(
        IPrincipalAccessor principalAccessor,
        IMultiTenancyConfig multiTenancy,
        ITenantResolver tenantResolver,
        IAmbientScopeProvider<SessionOverride> sessionOverrideScopeProvider) :
        base(principalAccessor, multiTenancy, tenantResolver, sessionOverrideScopeProvider)
    {

    }

    public string EmailAddress
        {
        get
        {
            var userEmailClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == "EmailAddress");
            if (string.IsNullOrEmpty(userEmailClaim?.Value))
            {
                return null;
            }

            return userEmailClaim.Value;
        }
    }

how to get EmailAddress value project.Applictaion page


6 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Define your own session and add your custom field to it Then, you can inject MyAppSession and use it's new property in your project.

    see:https://gist.github.com/ismcagdas/6f2a9a3b5d7b907cb8d94a72124d59a1

  • User Avatar
    0
    kalidarscope created

    How can i use the session and get the injected values from session in Project.Application folder.

    Noted : i am useing ASP.NET Core & Angular

  • User Avatar
    0
    aaron created
    Support Team

    ASAPSessions11.EmailAddress

  • User Avatar
    0
    kalidarscope created

    i can't geting EmailAddress

  • User Avatar
    1
    aaron created
    Support Team

    Inject an instance.

  • User Avatar
    0
    kalidarscope created

    Thanks