Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net Boilerplate,, How to Get current Login User?

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??

like image 420
MMG Avatar asked Dec 03 '22 12:12

MMG


2 Answers

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

 AbpSession.UserId
like image 103
Abdus Salam Azad Avatar answered Dec 05 '22 02:12

Abdus Salam Azad


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

like image 32
Alper Ebicoglu Avatar answered Dec 05 '22 02:12

Alper Ebicoglu