我如何创建用于多个页面的登录用户控件?

时间:2010-01-10 18:42:59

标签: asp.net-mvc

我想在asp.net mvc网站中创建登录用户控件,以便在多个页面中使用  对于普通页面,我有视图,控制器,模型我将如何处理这个用户控件的所有这些东西

2 个答案:

答案 0 :(得分:0)

<% if(User.IsAuthenticated) { %>
  <%-- User is logged in, show them the sidebar to do with their account --%>
  <% Html.RenderPartial("Sidebar/LoggedInSidebar"); %>
<% } else { %>
  <%-- User needs to log in, show them a sidebar that asks for their credentials --%>
  <% Html.RenderPartial("Sidebar/LogInSidebar"); %>
<% }
  • LoggedInSidebar指向~/Views/Shared/Sidebar/LoggedInSidebar.ascx
  • LogInSidebar指向~/Views/Shared/Sidebar/LogInSidebar.ascx

答案 1 :(得分:0)

愚蠢的问题@Ahmed但您不能使用创建新MVC项目时生成的那个吗?

它位于名为LogOnUserControl.ascx的共享文件夹中。