问题
Currently, AbpSession
only provides UserId
, but I want to use Username
instead because it is more explicit so how can I do that? Please help
回答1:
You can use UserManager class to retrieve the current user's information.
Example usage in an application service:
public async Task<string> GetCurrentUserName()
{
var user = await UserManager.FindByIdAsync(AbpSession.GetUserId().ToString());
return user.UserName;
}
If you want to use it in a custom class, then inject IAbpSession and UserManager classes.
来源:https://stackoverflow.com/questions/48247269/how-to-add-username-to-abpsession