簡體   English   中英

使用Web窗體使用自定義屬性更新IdentityUser之后。 如何顯示新的自定義屬性

[英]After updating IdentityUser with custom properties using Web Forms. How to display new custom property

跟隨此頁面( http://www.itorian.com/2013/11/customize-users-profile-in-aspnet.html )之后,我可以毫無問題地向我的身份用戶添加自定義屬性。 我遇到的問題是,之后我在網上可以找到的所有內容都與顯示MVC項目中的自定義屬性有關,但是我的項目是2015 ASP.NET Web Forms應用程序。 在母版頁中,有這段代碼顯示用戶名:

<li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName()  %> !</a>

我在身份配置文件中創建的自定義字段是FirstName和LastName。 我希望能夠像在上面的代碼中一樣在母版頁中顯示它們,而是顯示John Doe而不是JD_whateverLoginNameChosen。 我只是不太清楚如何正確訪問它。 謝謝您的幫助。

更新:我最終通過進入site.master頁面后面的代碼來完成此操作,而不是嘗試從aspx一側進行操作。 我還必須將鏈接從HTML鏈接更改為ASP HyperLink。 這是我用來做的代碼:

        protected void Page_Load(object sender, EventArgs e)
    {
        var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
        var currentUser = manager.FindById(Context.User.Identity.GetUserId());

        HyperLink h = ((HyperLink)this.loginViewMaster.FindControl("ManageLink"));
        if(currentUser != null)
        {
            h.Text = "Hello, " + currentUser.FirstName + " " + currentUser.LastName;


        }


    }

我最終通過進入site.master頁面后面的代碼來完成此操作,而不是嘗試從aspx一側進行操作。 我還必須將鏈接從HTML鏈接更改為ASP HyperLink。 這是我用來做的代碼:

        protected void Page_Load(object sender, EventArgs e)
{
    var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
    var currentUser = manager.FindById(Context.User.Identity.GetUserId());

    HyperLink h = ((HyperLink)this.loginViewMaster.FindControl("ManageLink"));
    if(currentUser != null)
    {
        h.Text = "Hello, " + currentUser.FirstName + " " + currentUser.LastName;


    }


}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM