2010-01-10 72 views
0

我要创建在asp.net mvc的网站登录用户控制的,以在多个页面 为正常的网页,我有视图,控制器,模型是如何,我会处理这一切的东西对该用户控件我如何创建登录用户控件以在多个页面中使用?

+0

你在找什么?将用户重定向到登录页面的逻辑? ASP.NET MVC自带的默认项目已经包含了这个。 – 2010-01-10 18:45:35

+0

我如何在用户控件中创建这个逻辑,以便在多个页面中的站点的侧栏中,ASP.NET MVC自带的默认项目包含默认页面,而不是用户控件 – Ahmed 2010-01-10 19:00:43

+0

我已经添加了一个我希望/想到的答案回答你的问题。欢迎来到Stack Overflow! :) – 2010-01-10 20:22:51

回答

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
0

愚蠢的问题@Ahmed,但你不能使用产生你的时候CREA的一个一个新的MVC项目?

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

+0

傻回复@griegs,因为我需要登录控制用户名/密码不是操作链接 – Ahmed 2010-01-11 07:04:20

相关问题