如何在没有C#主菜单的情况下将登录页面设置为我登陆的第一页

时间:2015-10-28 09:32:09

标签: c# asp.net asp.net-mvc razor layout

这是我在主要布局中的代码,但我不希望这些页面显示在我的登录页面中,我想要创建应用程序中显示的第一页。我想在登录后显示菜单。

<div class="navbar-collapse collapse">
   <ul class="nav navbar-nav" style="font:bold;">
      <li>@Html.ActionLink("Home", "Index", "Home")</li>
      <li>@Html.ActionLink("Vehicles", "Vehicles","Home")</li>
      <li>@Html.ActionLink("VehicleTrips","VehicleTrips","Home")</li>
      <li>@Html.ActionLink("Report","Index","Report")</li>
      <li>@Html.ActionLink("About", "About", "Home")</li>
      <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
      <li>@Html.ActionLink("OffVehicles", "OffVehicles", "Home")</li>
      <li>@Html.ActionLink("MovingState", "MovingState", "Home")</li>
   </ul>
   @Html.Partial("_LoginPartial")
</div>

1 个答案:

答案 0 :(得分:3)

如果您想共享布局,只需在视图中使用User.Identity.IsAuthenticated,如下所示:

@if(User.Identity.IsAuthenticated) { 
  <ul class="nav navbar-nav" style="font:bold;">
      <li>@Html.ActionLink("Home", "Index", "Home")</li>
      <li>@Html.ActionLink("Vehicles", "Vehicles","Home")</li>
      <li>@Html.ActionLink("VehicleTrips","VehicleTrips","Home")</li>
      <li>@Html.ActionLink("Report","Index","Report")</li>
      <li>@Html.ActionLink("About", "About", "Home")</li>
      <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
      <li>@Html.ActionLink("OffVehicles", "OffVehicles", "Home")</li>
      <li>@Html.ActionLink("MovingState", "MovingState", "Home")</li>
   </ul>
}

这会隐藏未经身份验证的用户的导航。