Base solution for your next web application
Open Closed

AbpSession Requirements #1573


User avatar
0
rickwheeler created

Hi,

What is required for an AbpSession to be populated on a controller?

I am creating a custom REST API that uses an API Key to authenticate users and I want my API controller to inherit from AbpApiController. So I need to know what to set in the pipeline in order for AbpSession to be populated on the ApiController. Does it use Thread.CurrentPrincipal?

Regards, Sean


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

    Hi,

    It was using Thread.CurrentPrincipal to get userid/tenantid until ABP v0.11. Now, it gets from HttpContext.Current.User.

    I will try to show related code:

    1. This is the default implementation of AbpSession: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Session/ClaimsAbpSession.cs">https://github.com/aspnetboilerplate/as ... Session.cs</a>

    2. It uses IPrincipalAccessor to get current Principal, which's default implementation gets from Thread.CurrentPrincipal: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Session/DefaultPrincipalAccessor.cs">https://github.com/aspnetboilerplate/as ... ccessor.cs</a>

    3. For MVC/Web API projects, it tries to get from HttpContext.Current if possible: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Web/Web/Session/HttpContextPrincipalAccessor.cs">https://github.com/aspnetboilerplate/as ... ccessor.cs</a>

    Hope that helps you to understand it.