首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MVC 5 Owin CAS注销操作不注销

MVC 5 Owin CAS注销操作不注销
EN

Stack Overflow用户
提问于 2017-06-07 03:40:37
回答 0查看 393关注 0票数 0

我正在尝试在我的MVC5应用程序中实现noelbundick's CAS authentication for Owin,但有一点小问题。我们希望这是您登录或注销的唯一方式,因此我们在没有身份验证的情况下启动了应用程序,并使用this tutorial设置了所有身份验证,还使用了另一个带有内置外部身份验证的新解决方案,作为比较我所做的工作的一种方式。

所以我用CAS换掉了所有谷歌的东西,一切都很好,除了某些原因,注销按钮不起作用。具体地说,这里的动作

代码语言:javascript
复制
// POST: /Account/LogOff
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
    return RedirectToAction("Index", "Home");
}

似乎跳过了SignOut()函数,直接转到RedirectToAction()。我会给你更多的代码,可能会有所帮助,但我真的不确定还有什么可以帮助你。第一段中的引用包含我使用过的所有代码,以及Visual Studio在具有外部身份验证的基本MVC站点上为您提供的任何默认代码。

身份验证管理器:

代码语言:javascript
复制
private IAuthenticationManager AuthenticationManager
{
    get { return HttpContext.GetOwinContext().Authentication; }
}

Startup.Auth.cs

代码语言:javascript
复制
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

代码语言:javascript
复制
public void Configuration(IAppBuilder app)
{
    ConfigureAuth(app);
}

ChallengeResult:

代码语言:javascript
复制
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上找不到解决方案,但这可能是因为我没有搜索到正确的术语,所以这也是受欢迎的。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44398524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档