【发布时间】:2017-11-07 23:21:20
【问题描述】:
我正在尝试在我的 MVC 5 应用程序中实现 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);
}
挑战结果:
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 上找不到解决方案,但这可能是因为我也没有在谷歌上搜索正确的术语,所以也欢迎这样做。
【问题讨论】:
标签: c# authentication asp.net-mvc-5 owin cas