Asp.Net Web窗体母版页上的访问用户自定义属性 [英] Asp.Net Web Forms access user custom properties on master page
问题描述
我如何能在主页上访问自定义用户属性(例如,姓,名),如果Web窗体项目使用的 Asp.Net识别系统?我已经做了这个配置 HTTP:// WWW。 itorian.com/2013/11/customize-users-profile-in-aspnet.html 的,但我的项目是不是MVC是Web窗体。
在默认情况下,我只能访问使用用户名:
Context.User.Identity.GetUserName()
没关系,我已经找到了答案。
在Site.Master.cs添加此行:
使用Microsoft.AspNet.Identity;
使用Microsoft.AspNet.Identity.Owin;
使用Owin;
使用EvSiProject.Models;
使用Microsoft.AspNet.Identity.EntityFramework;
然后添加此行对在Page_Load()函数:
如果(Context.User.Identity.IsAuthenticated)
{
VAR经理=新的UserManager< ApplicationUser>(新UserStore< ApplicationUser>(新ApplicationDbContext()));
变种的currentUser = manager.FindById(Context.User.Identity.GetUserId()); //字符串FNAME = currentUser.FirstName;
//字符串LNAME = currentUser.LastName;
}
这就是它。
How can I access custom user properties(eg. first name, last name) on the master page if the Web Forms Project is using Asp.Net Identity System? I've already made this configurations http://www.itorian.com/2013/11/customize-users-profile-in-aspnet.html but my project is not MVC is Web Forms.
By default I can only access user's name using:
Context.User.Identity.GetUserName()
Never mind, I've found the answer.
On Site.Master.cs add this lines:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using EvSiProject.Models;
using Microsoft.AspNet.Identity.EntityFramework;
Then add this lines on the Page_Load() function:
if (Context.User.Identity.IsAuthenticated)
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentUser = manager.FindById(Context.User.Identity.GetUserId());
//string fName = currentUser.FirstName;
//string lName = currentUser.LastName;
}
And that's it.
这篇关于Asp.Net Web窗体母版页上的访问用户自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!