6

I want to get the user data which is currently logged in,, ?? I have to send current user ID to a table in database How to do this??

Mesam Mujtaba
  • 114
  • 12
MMG
  • 151
  • 1
  • 3
  • 13

3 Answers3

12

You can use AbpSession to get user. For that you have to inject IAbpSession.You can use the following code:

 AbpSession.UserId
Abdus Salam Azad
  • 5,087
  • 46
  • 35
6

In custom classes use the code below to get current user id

public class MyClass : ITransientDependency
{
    public IAbpSession AbpSession { get; set; }

    public MyClass()
    {
        AbpSession = NullAbpSession.Instance;
    }

    public void MyMethod()
    {
        var currentUserId = AbpSession.UserId;
        //...
    }    

}

In application services you don't need to inject AbpSession just use AbpSession public property

AbpSession.TenantId

AbpSession.UserId

Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55
4

Here is the answer to the Question

User.Identity.GetUserId();
Mesam Mujtaba
  • 114
  • 12