首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在MVC环境中的MasterPage顶部显示欢迎"CurrentUserName"?

在MVC环境中的MasterPage顶部显示欢迎"CurrentUserName",可以通过以下步骤实现:

  1. 在MasterPage中添加一个Label或Literal控件,用于显示欢迎信息。
代码语言:html
复制
<asp:Label ID="lblWelcome" runat="server"></asp:Label>
  1. 在MasterPage的CodeBehind文件中,在Page_Load事件中添加以下代码:
代码语言:csharp
复制
protected void Page_Load(object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        string currentUserName = User.Identity.Name;
        lblWelcome.Text = "欢迎 " + currentUserName + "!";
    }
}

这样,在用户登录后,MasterPage顶部就会显示欢迎信息,包含当前用户的用户名。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的沙龙

领券