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

Custom Property Within abp.session inside Angular Client #11577


User avatar
0
asbbh created

I am using abpZero on Type 'ASP.NET CORE & Angular', Framework '.NET 7.0', and Version 'v12.1.0'.

I want to add some custom **abp.session ** so that I can use it inside the angular component.

How can I add an property as child of abp.session, where the data from table.


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @asbbh

    You can add this new property to GetCurrentLoginInformationsOutput on server side and return it via ISessionAppService. Then, on the client side, you can set abp.session.newProperty and use it in your app.

  • User Avatar
    0
    asbbh created

    HI,

    • I have added a property StaffId in src/SchoolAut0mater.Application.Shared/Sessions/Dto/GetCurrentLoginInformationsOutput.cs.
    • In src/SchoolAut0mater.Application/Sessions/SessionAppService.cs, I have initialize the value
    output.Tenant.SubscriptionDateString = GetTenantSubscriptionDateString(output);
                    output.Tenant.CreationTimeString = output.Tenant.CreationTime.ToString("d");
    
                    try
                    {
                        if (AbpSession.UserId.HasValue)
                        {
                            var emailAddress = $"{output.User.EmailAddress}".Trim();
                            var currentStaff = await _staffMasterRepo.FirstOrDefaultAsync(s => string.Equals(s.SchoolEmail, emailAddress));
                            if (currentStaff != null)
                            {
                                output.User.StaffId = currentStaff.Id;
                            }
                        }
                    }
                    catch { }
    

    But on client side I am not able to see any data in abp.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You also need to set it here https://github.com/aspnetzero/aspnet-zero-core/blob/dev/angular/src/shared/common/session/app-session.service.ts#L85.

    I suggest creating a new field in app-session.service.ts and use it in your app instead of defining a new field on abp.session.