【问题标题】:Asp.net mvc3:How to put username info in the Layour=t fileAsp.net mvc3:如何将用户名信息放入 Layour=t 文件中
【发布时间】:2012-06-01 14:56:17
【问题描述】:

我希望在布局文件的标题中显示当前登录的用户名。实现这一目标的最佳方法是什么?我目前没有将任何模型传递到布局文件中。另外,如果没有人登录,我不想明显显示用户名

【问题讨论】:

    标签: asp.net .net asp.net-mvc-3


    【解决方案1】:

    它位于默认模板的_LogOnPartial.cshtml 视图中!

    @if(Request.IsAuthenticated) {
        <text>Welcome <b>@Context.User.Identity.Name</b>!
        [ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
    }
    else {
        @:[ @Html.ActionLink("Log On", "LogOn", "Account") ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-25
      • 2013-03-18
      • 2012-07-04
      • 1970-01-01
      • 2021-07-20
      • 1970-01-01
      • 2020-10-07
      • 2020-12-17
      相关资源
      最近更新 更多