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

Need help about AbpSession #4986


User avatar
0
sago created

Hi,

After upgrading to Angular 5 abp-ng2-module, AbpSession.UserId value is null in my custom module while tenant id exists, however this value seems to be exists in SessionAppService. With my previous version this is working fine, please advise.

Regards,


13 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    try injecting the IAbpSession

    public class MyClass : ITransientDependency
    {
        public IAbpSession AbpSession { get; set; }
    
        public MyClass()
        {
            AbpSession = NullAbpSession.Instance;
        }
    
        public void MyMethod()
        {
            var currentUserId = AbpSession.UserId;
            //...
        }
    }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    @sago what is your abp-ng2-module version ? Your problem might not be related to abp-ng2-module.

    You can downgrade abp-ng2-module and see if it works for abp-ng2-module's older versions.

  • User Avatar
    0
    sago created

    <cite>alper: </cite> try injecting the IAbpSession

    public class MyClass : ITransientDependency
    {
       public IAbpSession AbpSession { get; set; }
    
       public MyClass()
       {
           AbpSession = NullAbpSession.Instance;
       }
    
       public void MyMethod()
       {
           var currentUserId = AbpSession.UserId;
           //...
       }
    }
    

    Injection is already exists through Base class

  • User Avatar
    0
    sago created

    <cite>ismcagdas: </cite> @sago what is your abp-ng2-module version ? Your problem might not be related to abp-ng2-module.

    You can downgrade abp-ng2-module and see if it works for abp-ng2-module's older versions.

    Downgraded didn't work, returned error Unexpected authenticateResult,

    Angular 4 with core 1.1 works without any issue, Angular 5 with core 1.1 Under ABPSession object TenantId exists UserId becomes Null..

  • User Avatar
    0
    ismcagdas created
    Support Team

    UserId must be retrieved from claims, see <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Session/ClaimsAbpSession.cs#L17">https://github.com/aspnetboilerplate/as ... ion.cs#L17</a>.

    Can you use same code and debug it to see if claims contains userId or not ?

  • User Avatar
    0
    sago created

    <cite>ismcagdas: </cite> UserId must be retrieved from claims, see <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Session/ClaimsAbpSession.cs#L17">https://github.com/aspnetboilerplate/as ... ion.cs#L17</a>.

    Can you use same code and debug it to see if claims contains userId or not ?

    The session values exists in UserAppService, and after navigating from this class to other custom service the Abpsession.UserId becomes Null and the user is UnAuthorized to access this service [AbpAuthorize]. The user is successfully Logged and he is granted this permission using Roles.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @sago,

    after navigating from this class to other custom service

    Can you explain this ? I couldn't understand it.

    It will be great if you can share your server-side and client-side code as well.

  • User Avatar
    0
    sago created

    <cite>ismcagdas: </cite> Hi @sago,

    after navigating from this class to other custom service

    Can you explain this ? I couldn't understand it.

    It will be great if you can share your server-side and client-side code as well.

    Okay ! I logged in to the application using admin privilleges, In the debug mode In UserAppService I can see all Session values, this class is decorated with attribute [AbpAuthorize()], when I navigate to the MyAppService the attribute [AbpAuthorize()] becomes InValid some how as it will not enter the requested method (decorated with attribute AbpAuthorize) and Session values are Null. This MyAppService is Inhierted from same base class ApplicationService. Again when I navigate to the UserAppService its Authorized and everything seems fine. I have problem with new created Services.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @sago we need to see your code to understand the problem. Because services in AspNet Zero don't have such a problem.

  • User Avatar
    0
    sago created

    <cite>ismcagdas: </cite> @sago we need to see your code to understand the problem. Because services in AspNet Zero don't have such a problem.

    I Agree with Abp.AspNetCore v 2.3.0 and Angular 4 everything is working fine with me. The AbpSession Null issue I am faccing after migrating to Angular v 5.2.9. I will share the code and update you, also appreciate If you guide me to any appropriate documentation for this Angular Upgradtion.

    Thanks,

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks. You can send codes to <a href="mailto:[email protected]">[email protected]</a>. We followed this page to update Angular to v5, <a class="postlink" href="https://angular-update-guide.firebaseapp.com/">https://angular-update-guide.firebaseapp.com/</a>.

  • User Avatar
    0
    sago created

    <cite>ismcagdas: </cite> @sago we need to see your code to understand the problem. Because services in AspNet Zero don't have such a problem.

    Issue resolved adding { provide: HTTP_INTERCEPTORS, useClass: AbpHttpInterceptor, multi: true } inside module, Thanks for your support !

  • User Avatar
    0
    alper created
    Support Team

    If you encounter any other problems, you can check out the GitHub commit for Upgrade to abp-ng2-module v2.0. <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-core-template/issues/187">https://github.com/aspnetboilerplate/mo ... issues/187</a>