显示的用户名以下是从标准的默认ASP.NET MVC项目由Visual Studio中创建的LogOn支持用户控件(LogOnUserControl.ascx):ASP.NET MVC从档案
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
if (Request.IsAuthenticated) {
%>
Welcome <b><%: Page.User.Identity.Name %></b>!
[ <%: Html.ActionLink("Log Off", "LogOff", "Account") %> ]
<%
}
else {
%>
[ <%: Html.ActionLink("Log On", "LogOn", "Account")%> ]
<%
}
%>
其被插入到一个主页:
<div id="logindisplay">
<% Html.RenderPartial("LogOnUserControl"); %>
</div>
的<%: Page.User.Identity.Name %>
代码显示登录名的用户的,当前请登录。
如何显示用户的FirstName
而不是保存在配置文件中?
我们可以在控制器类似如下阅读:
ViewData["FirstName"] = AccountProfile.CurrentUser.FirstName;
如果,例如,尝试做这样:
它使得仅被称为网页由控制器在ViewData["FirstName"]
值分配。
查看相关的链接:http://stackoverflow.com/questions/976493/asp-net-mvc-set-viewdata-for-masterpage-in-base-controller – 2010-10-27 18:55:20