我一直试图使用asp.net标识系统显示自定义用户属性。现在,我一直在关注本教程,也参考了这里发布的问题。请告诉我,我是非常新的ASP.NET网页编码。
我的问题是,我必须知道我应该在母版页上使用什么代码。
本教程中给出的代码包括
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using EvSiProject.Models;
using Microsoft.AspNet.Identity.EntityFramework;和
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;
}它将在后面的Site.Master.cs中使用。
我的问题是,我应该在Site.Master上使用什么代码来显示自定义属性。自定义属性作为地址存储在我的数据库中。
谢谢
发布于 2015-12-15 21:39:36
为了在母版页上显示它,您必须将标签添加到母版页的HTML视图中,如下所示:
<asp:Label runat="server" ID="lblAddress"></asp:Label>在这里,标签的Id对于在后面的代码中访问是很重要的。假设您在object currentUser的currentUser字段中拥有所需的数据。在后面的代码中,可以使用以下代码将地址字段中的数据分配给标签lblAddress。
lblAddress.Text = currentUser.Address;https://stackoverflow.com/questions/34299706
复制相似问题