【发布时间】:2016-09-26 19:40:31
【问题描述】:
我目前正在开发一个遵循复数视觉指南的网站。 Web 应用程序有两个主要问题:
-
注销后,以下
if语句下的项目仍然显示:@if (User.Identity.IsAuthenticated) { <li class="nav-item btn-group"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-user"></i> <span class="hidden-sm-down"> @User.Identity.Name </span> </a> <div class="dropdown-menu"> <a class="dropdown-item" asp-controller="Account" asp-action="Account"> Account <i class="fa fa-user" aria-hidden="true"></i> </a> <a class="dropdown-item" asp-controller="Settings" asp-action="Settings"> Settings <i class="fa fa-gear" aria-hidden="true"></i> </a> <div class="dropdown-divider"></div> <a class="dropdown-item" asp-controller="Logout" asp-action="Logout"> Logout <i class="fa fa-sign-out" aria-hidden="true"></i> </a> </div> </li> } -
第二个问题是对登录的用户隐藏菜单:
@if (!User.Identity.IsAuthenticated) { <li class="nav-item @(ViewContext.RouteData.Values["Controller"].ToString() == "Contact" ? "active" : "")"> <a class="nav-link" asp-controller="Contact" asp-action="Contact">Contact</a> </li> <li class="nav-item @(ViewContext.RouteData.Values["Controller"].ToString() == "About" ? "active" : "")"> <a class="nav-link" asp-controller="About" asp-action="About">About</a> </li> }
如果 User.Identity.IsAuthenticated 返回一个布尔值,我不确定为什么这不起作用。
Picture of my NavBar displaying menus after login out
如果需要,我会提供更多详细信息。提前谢谢!
【问题讨论】:
-
您能否尝试在您的
if语句上设置断点并检查以确保IsAuthenticated的值正确?您是否尝试过其他任何方法来找出造成这种情况的原因? -
另外,我复制粘贴了你在这里的内容,我正在使用 Windows 身份验证,我只是看到了第一个
if的内容,正如我所期望的那样,因为我已登录。User.Identity.IsAuthenticated对我来说是true。 (我也在使用 fontawesome 所以我看到了图标,但这并不重要) -
那么当单击注销时,剃刀布局视图会在异步公共异步任务
Logout() 完成之前呈现? -
我不确定,我根本没有尝试注销,我只是粘贴了你的代码并点击运行,因为我是通过 Windows 身份验证自动登录的,所以我只看到在检查
User.Identity.IsAuthenticated的if中的第一部分。 -
对于我的第一个问题,如果我刷新页面,用户名下拉菜单会按预期消失。但我希望它在他们被重定向到注销页面后立即消失。
标签: c# .net asp.net-mvc razor asp.net-identity