MVC 5 Owin CAS注销操作没有注销

问题描述:

我试图在我的MVC 5应用程序中实现noelbundick's CAS authentication for Owin,但带来了麻烦。我们希望这是您登录或注销的唯一方式,因此我们在没有身份验证的情况下启动了应用程序,并使用this tutorial来设置所有身份验证,同时使用另一种带有内置外部身份验证的新解决方案比较我在做什么。MVC 5 Owin CAS注销操作没有注销

所以我已经用CAS的东西切换出所有谷歌的东西,并且一切都很好,除了某些原因外,注销按钮不起作用。具体而言,这里的行动

// POST: /Account/LogOff 
[HttpPost] 
[ValidateAntiForgeryToken] 
public ActionResult LogOff() 
{ 
    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); 
    return RedirectToAction("Index", "Home"); 
} 

似乎跳过了SignOut()功能,并直接进入RedirectToAction()。我会再给你一些可能有用的代码,但我真的不知道还有什么可以帮助的。第一段中的引用包含我使用过的所有代码,以及任何Visual Studio在带有外部认证的基本MVC站点上提供的任何默认代码。

认证管理器:

private IAuthenticationManager AuthenticationManager 
{ 
    get { return HttpContext.GetOwinContext().Authentication; } 
} 

Startup.Auth.cs

private void ConfigureAuth(IAppBuilder app) 
{ 
    var cookieOptions = new CookieAuthenticationOptions 
    { 
     LoginPath = new PathString("/Account/Login") 
    }; 
    app.UseCookieAuthentication(cookieOptions); 
    app.SetDefaultSignInAsAuthenticationType(cookieOptions.AuthenticationType); 
    CasAuthenticationOptions casOptions = new CasAuthenticationOptions() 
    { 
     CasServerUrlBase = "https://cas.ourserver.com/cas" 
    }; 
    app.UseCasAuthentication(casOptions); 
} 

Startup.cs

public void Configuration(IAppBuilder app) 
{ 
    ConfigureAuth(app); 
} 

ChallengeResult:

private class ChallengeResult : HttpUnauthorizedResult 
{ 
    public ChallengeResult(string provider, string redirectUri) 
    { 
     LoginProvider = provider; 
     RedirectUri = redirectUri; 
    } 
    public string LoginProvider { get; set; } 
    public string RedirectUri { get; set; } 
    public override void ExecuteResult(ControllerContext context) 
    { 
     var properties = new AuthenticationProperties() { RedirectUri = RedirectUri }; 
     context.HttpContext.GetOwinContext() 
      .Authentication.Challenge(properties, LoginProvider); 
    } 
} 

要清楚,我不需要它注销CAS服务器,只需登录网站即可。如果CAS cookie仍然存在,那很好。问题是它仍然说“欢迎,用户!”和“注销”在顶部。

请让我知道,如果有什么我可以给你,这将有所帮助。我搜索了一切,找不到解决方案在线或*,但这可能是因为我没有谷歌正确的条款,所以这也是值得欢迎的。

我是想一百万个不同的解决方案,并在我当前的代码我有

// POST: /Account/LogOff 
[HttpPost] 
[ValidateAntiForgeryToken] 
public ActionResult LogOff() 
{ 
    //AuthenticationManager.SignOut(
    // DefaultAuthenticationTypes.ApplicationCookie, 
    // DefaultAuthenticationTypes.ExternalCookie); 
    //Session.Abandon(); 
    //return RedirectToAction("Index", "Home"); 

    HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); 
    HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
    HttpContext.Response.Cache.SetNoStore(); 

    Session.Clear(); 
    Session.Abandon(); 
    Session.RemoveAll(); 
    FormsAuthentication.SignOut(); 
    return RedirectToAction("Index", "Home"); 
} 

当我改回了上述原注销等动作,它的工作所有的突然。抱歉!