【问题标题】:How to get user profile data from ASP.NET MVC custom IdentityUser Model?如何从 ASP.NET MVC 自定义 IdentityUser 模型中获取用户配置文件数据?
【发布时间】:2015-07-24 20:44:34
【问题描述】:

this blog 的帮助下,我向 ApplicationUser 类(在 IdentityModels.cs 文件中)添加了一个自定义配置文件属性 OfficeKey

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

      //remaining code here
}

我可以这样获取用户名:

   User.Identity.Name

如何获取自定义用户数据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?

注意:这是一个带有 MySQL 成员资格提供程序的 ASP.NET MVC 5 Web 应用程序。

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-membership asp.net-identity


    【解决方案1】:

    如果您将UserManager 配置为ApplicationUser,它将向用户返回如下信息:

     // Create manager
     var manager = new UserManager<ApplicationUser>(
        new UserStore<ApplicationUser>(
            new ApplicationDbContext()))
    
    // Find user
    var user = manager.FindById(User.Identity.GetUserId());
    

    OfficeKey 将在用户中可用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      • 1970-01-01
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多