如何将用户名添加到 AbpSession [英] How to add Username to AbpSession
本文介绍了如何将用户名添加到 AbpSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,AbpSession
仅提供 UserId
,但我想改用 Username
,因为它更明确,所以我该怎么做?请帮忙
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
推荐答案
您可以使用 UserManager 类来检索当前用户的信息.
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;
}
如果您想在自定义类中使用它,请注入 IAbpSession 和 UserManager 类.
If you want to use it in a custom class, then inject IAbpSession and UserManager classes.
这篇关于如何将用户名添加到 AbpSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文