如何从ASP.NET MVC定制IdentityUser型号的用户配置文件数据? [英] How to get user profile data from ASP.NET MVC custom IdentityUser Model?
问题描述
随着<一个帮助href=\"http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx\"相对=nofollow>这个博客,我添加了一个自定义配置文件属性的 OfficeKey 以ApplicationUser类(在IdentityModels.cs文件):
公共类ApplicationUser:IdentityUser
{
公众诠释OfficeKey {搞定;组; } //剩余code在这里
}
我能得到的用户名是这样的:
User.Identity.Name
的我要如何自定义用户数据的 OfficeKey ?的
块引用>我尝试了这些:
<一个href=\"http://stackoverflow.com/questions/23288879/how-to-get-identity-user-data-from-asp-net-mvc-model\">How从获取用户身份的数据Asp.net MVC模式
<一个href=\"http://stackoverflow.com/questions/3761682/how-to-get-user-email-address-from-asp-net-mvc-default-mempership-model\">How从ASP.NET MVC默认Mempership模式获得用户的电子邮件地址?
注:这是与MySQL成员提供一个ASP.NET MVC 5 Web应用程序
解决方案如果您配置
的UserManager
与ApplicationUser
它将与信息返回用户如下://创建经理
VAR经理=新的UserManager&LT; ApplicationUser&GT;(
新UserStore&LT; ApplicationUser&GT;(
新ApplicationDbContext()))//查找用户
变种用户= manager.FindById(User.Identity.GetUserId());的
OfficeKey
将在用户使用。With the help of this blog, I have added a custom profile property OfficeKey to ApplicationUser class (in IdentityModels.cs file):
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?
I have tried these:
How to get Identity User Data from Asp.net mvc Model
How to get user email address from ASP.NET MVC Default Mempership Model?
NB: It is an ASP.NET MVC 5 web application with MySQL membership provider.
解决方案If you configure the
UserManager
with theApplicationUser
it will return the user with the information as follows:// 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.这篇关于如何从ASP.NET MVC定制IdentityUser型号的用户配置文件数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!