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??
Asked
Active
Viewed 7,421 times
3 Answers
7
You can use AbpSession to get user. For that you have to inject IAbpSession.You can use the following code:
AbpSession.UserId
![](../../users/profiles/2738695.webp)
Abdus Salam Azad
- 3,109
- 31
- 23
-
As a note, you can also use the AbpSession property available if you inherited some Abp service or controller – FindOutIslamNow Dec 22 '20 at 11:14
5
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
![](../../users/profiles/1767482.webp)
Alper Ebicoglu
- 6,488
- 1
- 34
- 39
-
As a note, you can also use the AbpSession property available if you inherited some Abp service or controller – FindOutIslamNow Dec 22 '20 at 11:17