c# - 我如何将登录页面设置为我在 C# 中没有主菜单的第一页

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

最佳答案

如果您想共享布局,只需在您的 View 中使用 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>
}

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

关于c# - 我如何将登录页面设置为我在 C# 中没有主菜单的第一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33387378/

相关文章:

c# - 在线crm动态,将自定义url参数传递给插件

c# - 通过网络从 Xbox Kinect 流式传输视频

c# - 如何在 web.config 中引用 DLL?

javascript - 使用 Ajax 将多个对象发送到 ASP.NET MVC Controller

c# - 导入的类型被定义多次 - 仅在 Mono 2.10.1 的 xbuild 下

C# WebClient 返回损坏的非英语文本

asp.net - 不寻常的 :hover behavior (IE 8)

c# - 当前上下文中不存在路径 c# .net 编码?

c# - Sendgrid 系统.ArgumentException : Unknown element: html

asp.net-mvc - 有没有办法使用符号服务器调试 ASP.NET MVC 代码(而不是下载源代码并引用它)?