简体   繁体   中英

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

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

以下是该课题的答案

User.Identity.GetUserId();

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

 AbpSession.UserId

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM