[英]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.