我正在尝试在我的MVC5应用程序中实现noelbundick's CAS authentication for Owin,但有一点小问题。我们希望这是您登录或注销的唯一方式,因此我们在没有身份验证的情况下启动了应用程序,并使用this tutorial设置了所有身份验证,还使用了另一个带有内置外部身份验证的新解决方案,作为比较我所做的工作的一种方式。
所以我用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保留下来也没关系。问题是它仍然写着“欢迎,用户!”和顶部的“注销”。
如果还有什么我能给你的,请告诉我。我已经用谷歌搜索了所有东西,但在网上或StackOverflow上找不到解决方案,但这可能是因为我没有搜索到正确的术语,所以这也是受欢迎的。
https://stackoverflow.com/questions/44398524
复制相似问题