如何将用户名添加到AbpSession [英] How to add Username to AbpSession

查看:468
本文介绍了如何将用户名添加到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆