Windows身份基础 - 注销或更新声明

Sea*_*ean 1 c# wif

我正在使用Windows Identity Foundation管理我们网站的登录.

当用户登录时,我正在使用他的请求中的一些信息来提出索赔.一切正常,但现在我需要管理这个场景:

  1. 用户已登录,身份验证且具有有效令牌.
  2. 但是用户决定再次浏览(通过来自其他网站的重定向)
  3. 所以他在他的请求中的信息是不同的.
  4. 我想要
    • 签下他 - 这样他就可以自然地用他的新信息创建一个新的令牌
    • 或者更新他现有的令牌.

所以我的问题是:

  1. 我如何退出Windows Identity基础?
  2. 或者如何更新现有声明?

我试过这段代码:

  public void ExpireClaims(HttpContextBase httpContextBase)
    {
        var module =
            httpContextBase.ApplicationInstance.Modules["WSFederationAuthenticationModule"] as
            WSFederationAuthenticationModule;
        if (module == null)
        {
            return;
        }
        module.SignOut(true);
    }
Run Code Online (Sandbox Code Playgroud)

但模块总是空的.

我试过这个:

  public void FederatedSignOut(string replyUrl)
    {
        WSFederationAuthenticationModule.FederatedSignOut(null, new Uri(replyUrl));
    }
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我得到一个空的引用execption.

非常感谢.

nzp*_*mad 8

基本上注销只是删除cookie所以:

FormsAuthentication.SignOut

要么

FederatedAuthentication.SessionAuthenticationModule.SignOut

要么

FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie

将工作.

或者使用FederatedPassiveSignInStatus(应该在你的工具箱中).将属性设置SignOutActionFederatedSignOut,控件将清除您的STS会话.