简体   繁体   English

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

[英]how do i set the login page to be the first page i land on without the main menu in C#

This is the code i have in my Main Layout but i don't want these pages to appear in my Login Page that i want to make the first page that appears in my application. 这是我在主布局中的代码,但我不希望这些页面出现在我想要创建应用程序中出现的第一页的登录页面中。 I want the menu to appear after login. 我希望登录后显示菜单。

<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>

If you want to share the layout you could simply use User.Identity.IsAuthenticated in your view as follows: 如果要共享布局,只需在视图中使用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>
}

This would hide the navigation for unauthenticated users. 这将隐藏未经身份验证的用户的导航。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM