简体   繁体   English

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

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

With the help of this blog , I have added a custom profile property OfficeKey to ApplicationUser class (in IdentityModels.cs file): 这篇博客的帮助下,我在ApplicationUser类中添加了一个自定义配置文件属性OfficeKey (在IdentityModels.cs文件中):

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

      //remaining code here
}

I can get user name like this: 我可以得到这样的用户名:

   User.Identity.Name

How do I get custom user data OfficeKey ? 如何获取自定义用户数据OfficeKey

I have tried these: 我试过这些:

How to get Identity User Data from Asp.net mvc Model 如何从Asp.net mvc Model获取身份用户数据

How to get user email address from ASP.NET MVC Default Mempership Model? 如何从ASP.NET MVC默认Mempership模型获取用户电子邮件地址?

NB: It is an ASP.NET MVC 5 web application with MySQL membership provider. 注意:它是一个带有MySQL成员资格提供程序的ASP.NET MVC 5 Web应用程序。

If you configure the UserManager with the ApplicationUser it will return the user with the information as follows: 如果使用ApplicationUser配置UserManager ,它将返回具有以下信息的用户:

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

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

The OfficeKey will be available in the user. OfficeKey将在用户中可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 IdentityUser 与 ASP.NET MVC 中的配方连接起来 - How can I connect IdentityUser with Recipe in ASP.NET MVC ASP.NET MVC 5 IdentityUser相关实体 - ASP.NET MVC 5 IdentityUser related entity 无法从ASP.NET Core 2.1控制器获取IdentityUser数据 - Unable to get IdentityUser data from ASP.NET Core 2.1 controller 如何从ASP.NET MVC RC1中的ViewResult获取模型数据? - How to get model data from a ViewResult in ASP.NET MVC RC1? 如何从 Asp.net 核心 Razor 页面中的 IdentityUser 列表中获取没有角色的用户 - How to Get the Users with No Role from IdentityUser List in Asp.net Core Razor Pages 我如何将现有模型(设备)数据附加到MVC ASP.NET中的另一个模型(用户)数据 - How can i attach existing model(device) data to another model(user) data in mvc asp.net 从 Asp Net MVC 中的 IdentityUser 中排除 email - Exclude email from IdentityUser in Asp Net MVC Asp.Net Core Identity、IdentityUser.Email 与 UserManage<identityuser> .GetEmailAsync(IdentityUser 用户)</identityuser> - Asp.Net Core Identity, IdentityUser.Email versus UserManage<IdentityUser>.GetEmailAsync(IdentityUser user) 用于GET请求的ASP.NET MVC的自定义模型Binder - Custom Model Binder for ASP.NET MVC on GET request 如何使用 MVC 模型绑定从 Asp.net MVC 中的 SendGrid Inbound Parse Webhook 获取数据? - How do I use MVC model binding to get data from SendGrid Inbound Parse Webhook in Asp.net MVC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM