How to add Username to AbpSession

梦想的初衷 提交于 2020-01-05 07:26:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!