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

Add extra field to AbpSession #584


User avatar
0
omital created

Hi, How can I add extra filed to abpSession . for example I want to force user to select (current fiscal year) in login page and store it in session .


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

    Do you use module-zero? I assume yes. If so, I suggest to use claims to store session variables. Then you can store claims in cookie or token based on your client.

    See <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/blob/master/src/AbpCompanyName.AbpProjectName.WebSpaAngular/Controllers/AccountController.cs#L150">https://github.com/aspnetboilerplate/mo ... er.cs#L150</a>

    Here, SignInAsync method creates identity then stores in the cookie. You can add more by identity.Claims.Add(...). How? Example: <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/master/src/Abp.Zero/Authorization/Users/AbpUserManager.cs#L488">https://github.com/aspnetboilerplate/mo ... er.cs#L488</a>

    Then you can get claims from next request. Example: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/8cfbde6911cf3f7b12a0b8de464a782fd76d7e39/src/Abp/Runtime/Session/ClaimsAbpSession.cs#L50">https://github.com/aspnetboilerplate/as ... ion.cs#L50</a>

    So, this way you can store/get session values. Where to do it? You can simple create your own interface and class, like IMyAppSession and MyAppSession, and define properties (like TenantId above). If you want, you can extend built-in session classes. If you use module-zero then extend IdentityFrameworkClaimsAbpSession class (<a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/master/src/Abp.Zero/Runtime/Session/IdentityFrameworkClaimsAbpSession.cs#L11">https://github.com/aspnetboilerplate/mo ... ion.cs#L11</a>).

  • User Avatar
    0
    omital created

    Thank you for your complete response. I will work on it.

  • User Avatar
    0
    hikalkan created
    Support Team

    See a simple implementation: <a class="postlink" href="https://gist.github.com/hikalkan/67469e05475c2d18cb88">https://gist.github.com/hikalkan/67469e05475c2d18cb88</a>