Asp.net 前台显示自定义属性标识
Asp.net Front display custom properties identity
我一直在尝试使用 asp.net 身份系统显示自定义用户属性。现在我一直在关注 This tutorial and also refering to the question posted 。请注意,我是 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 处使用什么代码来显示自定义 属性。自定义 属性 在我的数据库中存储为地址。
谢谢
为了在母版页上显示它,您必须将标签添加到母版页的 HTML 视图中,如下所示:
<asp:Label runat="server" ID="lblAddress"></asp:Label>
在这里,标签的 ID 很重要,可以在代码隐藏中访问。
假设您在对象 currentUser
的 Address
字段中有所需的数据。
在后面的代码中,您可以使用以下代码将地址字段中的数据分配给标签 lblAddress
.
lblAddress.Text = currentUser.Address;
我一直在尝试使用 asp.net 身份系统显示自定义用户属性。现在我一直在关注 This tutorial and also refering to the question posted
我的问题是我必须知道我应该在母版页上使用什么代码。
教程中给出的代码是
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 处使用什么代码来显示自定义 属性。自定义 属性 在我的数据库中存储为地址。
谢谢
为了在母版页上显示它,您必须将标签添加到母版页的 HTML 视图中,如下所示:
<asp:Label runat="server" ID="lblAddress"></asp:Label>
在这里,标签的 ID 很重要,可以在代码隐藏中访问。
假设您在对象 currentUser
的 Address
字段中有所需的数据。
在后面的代码中,您可以使用以下代码将地址字段中的数据分配给标签 lblAddress
.
lblAddress.Text = currentUser.Address;