如何从 ASP.NET MVC 自定义 IdentityUser 模型获取用户配置文件数据?

How to get user profile data from ASP.NET MVC custom IdentityUser Model?

this blog 的帮助下,我已将自定义配置文件 属性 OfficeKey 添加到 ApplicationUser class(在 IdentityModels.cs 文件):

public class ApplicationUser : IdentityUser
{
      public int OfficeKey { get; set; }

      //remaining code here
}

我可以这样获取用户名:

   User.Identity.Name

How do I get custom user data OfficeKey?

我试过这些:

How to get Identity User Data from Asp.net mvc Model

How to get user email address from ASP.NET MVC Default Mempership Model?

注意: 这是一个 ASP.NET MVC 5 网络应用程序,具有 MySQL 成员提供程序。

如果您使用 ApplicationUser 配置 UserManager,它将 return 用户提供如下信息:

 // Create manager
 var manager = new UserManager<ApplicationUser>(
    new UserStore<ApplicationUser>(
        new ApplicationDbContext()))

// Find user
var user = manager.FindById(User.Identity.GetUserId());

OfficeKey 将在用户中可用。