如何从用户名更改的ASP.Net的问候消息名字或任何其他方面? [英] How to change the greeting message on ASP.Net from UserName to First Name or any other field?

查看:152
本文介绍了如何从用户名更改的ASP.Net的问候消息名字或任何其他方面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能改变下面提到code显示:你好,名,而不是你好用户名

How can I change the below mentioned code to show: Hello "First Name" instead of Hello "UserName".

我已经创建了我的身份用户表里面的一些自定义字段,如名字,中间名,姓氏。

I have already created some custom fields inside my Identity user table such as "FirstName","MiddleName","LastName".

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

我AP preciate您在达成解决我的问题的努力。

I appreciate your efforts in reaching a solution for my problem.

推荐答案

首先,在添加 Microsoft.AspNet.Identity.Owin 命名空间的web.config

First Add Microsoft.AspNet.Identity.Owin namespace in web.config

<configuration>
   <namespaces>
       <!-- other namespaces -->
       <add namespace="Microsoft.AspNet.Identity.Owin"/>
  </namespaces>
</configuration>

然后更换您的code:

then replace your code with:

<li>
    <a runat="server" href="~/Account/Manage" title="Manage your account"> Hello,
        <%: HttpContext.Current.GetOwinContext()
            .GetUserManager<YourNamespace.ApplicationUserManager>()
            .FindById(Context.User.Identity.GetUserId()).FirstName %>!
   </a>
</li>

这篇关于如何从用户名更改的ASP.Net的问候消息名字或任何其他方面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆