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)
-
0
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:
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>
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>
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.