MVC 5 Owin CAS 注销操作不会注销
MVC 5 Owin CAS Logoff action doesn't log off
我正在尝试实施 noelbundick's CAS authentication for Owin in my MVC 5 application, but with a twist. We want this to be the only way you can log in or out, so we started the application with no authentication, and used this tutorial 来设置所有身份验证,同时使用另一个带有内置外部身份验证的新解决方案来比较我正在做的事情。
所以我用 CAS 东西换掉了所有 google 东西,一切都很好,除了出于某种原因,注销按钮不起作用。具体来说,这里的动作
// 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 保留,那很好。问题是它仍然在顶部显示 "Welcome, User!" 和 "Log off"。
如果我还有什么可以帮助您的,请告诉我。我已经 google 了解了所有内容,但无法在线或在 Whosebug 上找到解决方案,但这可能是因为我也没有 google 正确的条款,所以也欢迎。
我尝试了一百万种不同的解决方案,而在我当前的代码中我有
// 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");
}
当我将其改回上面原来的注销操作时,它突然起作用了。抱歉!
我正在尝试实施 noelbundick's CAS authentication for Owin in my MVC 5 application, but with a twist. We want this to be the only way you can log in or out, so we started the application with no authentication, and used this tutorial 来设置所有身份验证,同时使用另一个带有内置外部身份验证的新解决方案来比较我正在做的事情。
所以我用 CAS 东西换掉了所有 google 东西,一切都很好,除了出于某种原因,注销按钮不起作用。具体来说,这里的动作
// 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 保留,那很好。问题是它仍然在顶部显示 "Welcome, User!" 和 "Log off"。
如果我还有什么可以帮助您的,请告诉我。我已经 google 了解了所有内容,但无法在线或在 Whosebug 上找到解决方案,但这可能是因为我也没有 google 正确的条款,所以也欢迎。
我尝试了一百万种不同的解决方案,而在我当前的代码中我有
// 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");
}
当我将其改回上面原来的注销操作时,它突然起作用了。抱歉!