2011-11-07 30 views
1

我使用Windows Identity Foundation来管理登录我们的网站。Windows身份基础 - 注销或更新声明

当用户登录时,我在他的请求中使用了一些信息来放入索赔。 这是所有工作正常,但现在我需要管理这样的情景:

  1. 用户已经登录,athenticated并具有有效的令牌。
  2. 但用户决定再次浏览(通过从另一个网站重定向)
  3. 因此,他在他的请求中的信息是不同的。
  4. 我想要么
    • 他签 - 所以,他会自然地产生一个新的令牌与他的新信息
    • 或更新其现有的令牌。

所以我的问题是:

  1. 我如何注册了Windows身份验证的基础?
  2. 或者我如何更新现有的索赔?

我曾尝试这样的代码:

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

但模块常是空。

和我想这:

public void FederatedSignOut(string replyUrl) 
    { 
     WSFederationAuthenticationModule.FederatedSignOut(null, new Uri(replyUrl)); 
    } 

但我得到一个空引用execption当我做到这一点。

非常感谢。

回答

8

本质上登出只是删除的cookie这样:

FormsAuthentication.SignOut

FederatedAuthentication.SessionAuthenticationModule.SignOut

FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie

会工作。

或使用FederatedPassiveSignInStatus(应在您的工具箱中)。将属性SignOutAction设置为FederatedSignOut,控件也会清除您的STS会话。

+0

谢谢,优秀的答案!我正在使用FederatedAuthentication.SessionAutheticationModule.SignOut。我注意到,只是使用FormsAuthentication.SignOut仍然允许用户访问联合网站,而不是您当前所在的网站。还将调查最终选项。再次感谢。 – Sean

+0

毕竟,上述方法只能让我脱离当前的依赖方。他们没有把我从所有的依赖方中签出来。我必须在sts中实现自己的自定义联合签名。这里是我的另一个问题的链接:http://stackoverflow.com/questions/8228746/wif-federatedsignout-not-signing-user-out-all-sites – Sean

+0

此外,我发现你不能更新索赔,一旦你创建令牌。从安全的角度来看,这似乎是明智的行为! – Sean

相关问题