我的项目基于Visual Studio 2013的MVC 5项目模板(个人用户帐户选项).我一直依赖于我的用户的默认登录和注销方法.但我不确定我做了什么,在某些时候,用户不能再退出,但他们可以作为另一个用户登录.
这是帐户控制器的默认Logoff方法
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
AuthenticationManager.SignOut();
return RedirectToAction("Index", "Home");
}
private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}
Run Code Online (Sandbox Code Playgroud)
这是显示用户用户名的默认_LoginPartial.cshtml视图.
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
<li>
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a> </li>
</ul>
}
}
else
{
<ul …Run Code Online (Sandbox Code Playgroud)