MVC AuthenticationManager.SignOut()未注销 [英] MVC AuthenticationManager.SignOut() is not signing out

查看:108
本文介绍了MVC AuthenticationManager.SignOut()未注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目基于Visual Studio 2013中的MVC 5项目模板(单个用户帐户选项).我一直为我的用户使用默认的登录和注销方法.但是我不确定我做了什么,在某些时候,用户无法再注销,但是他们可以以其他用户身份登录.

My project is based on the MVC 5 project template from Visual Studio 2013 (individual user account option). I have been relying on the default Sign In and Sign Out method for my users. But I'm not sure what I did, at some point, users cannot sign out anymore, however they can sign in as another user.

这是帐户控制器的默认注销方法

This is the default Logoff method of Account Controller

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult LogOff()
    {
        AuthenticationManager.SignOut();
        return RedirectToAction("Index", "Home");
    }
    private IAuthenticationManager AuthenticationManager
    {
        get
        {
            return HttpContext.GetOwinContext().Authentication;
        }
    }

这是显示用户名的默认_LoginPartial.cshtml视图.

This is the default _LoginPartial.cshtml View that shows user's username.

    @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 class="nav navbar-nav navbar-right">
            <li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
            <li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
        </ul>
    }

当用户注销时,它将用户引导到登录页面,但是仍然显示用户名,这表示他们尚未注销.浏览器上的网址显示 http://localhost/Account/Login?ReturnUrl =%2FAccount%2FLogOff

When user signs out, it directs user to the login page, but user's username is still shown which means that they have not signed out. And the url on the browser shows http://localhost/Account/Login?ReturnUrl=%2FAccount%2FLogOff

这不会使用户返回首页的索引页面.所以我的猜测是在AuthenticationManager.SignOut();语句中发生了什么.我很困惑,因为我没有更改帐户控制器的任何内容.

It is not taking the user back to Index page of Home. So my guess is that something happened at the statement AuthenticationManager.SignOut();. I'm confused because I haven't changed anything to the Account Controller.

任何线索都将不胜感激.

Any lead would be greatly appreciated.

推荐答案

我遇到了同样的问题. 在CodePlex上检查此问题:

I had the same problem. Check this Issue on CodePlex:

http://web.archive.org/web/20160403071605/https://aspnetidentity.codeplex .com/workitem/2347

尝试将AuthenticationManager.SignOut()替换为 AuthenticationManager.Signout(DefaultAuthenticationTypes.ApplicationCookie);

我希望能对您有所帮助. :-)

I hope that I help you. :-)

这篇关于MVC AuthenticationManager.SignOut()未注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆