c# – 如何从ASP.NET MVC自定义IdentityUser模型获取用户配置文
发布时间:2020-12-15 04:11:00 所属栏目:百科 来源:网络整理
导读:在 this blog的帮助下,我向ApplicationUser类添加了一个自定义配置文件属性OfficeKey(在IdentityModels.cs文件中): public class ApplicationUser : IdentityUser{ public int OfficeKey { get; set; } //remaining code here} 我可以得到这样的用户名: Us
在
this blog的帮助下,我向ApplicationUser类添加了一个自定义配置文件属性OfficeKey(在IdentityModels.cs文件中):
public class ApplicationUser : IdentityUser { public int OfficeKey { get; set; } //remaining code here } 我可以得到这样的用户名: User.Identity.Name
我试过这些: 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应用程序. 解决方法
如果使用ApplicationUser配置UserManager,它将返回具有以下信息的用户:
// Create manager var manager = new UserManager<ApplicationUser>( new UserStore<ApplicationUser>( new ApplicationDbContext())) // Find user var user = manager.FindById(User.Identity.GetUserId()); OfficeKey将在用户中可用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |