【问题标题】:Claims Aware MVC App in 2012 - Logging off2012 年的 Claims Aware MVC 应用程序 - 注销
【发布时间】:2013-10-03 21:38:02
【问题描述】:

我在 .net 4.5 中创建了一个 MVC 4 应用程序并安装了身份和访问工具,以便我可以创建一个声明感知应用程序。我配置了应用程序,使其使用 2012 年附带的新 LocalSTS,因此它不会像 2010 年那样创建 STS 网站。

如何在我的应用程序中支持注销方案?有没有像FormsAuthentication.SignOut 这样我可以调用的方法?

【问题讨论】:

    标签: c# asp.net-mvc visual-studio-2012 wif


    【解决方案1】:

    真的很简单,只需调用 WSFederationAuthenticationModule 上的 SignOut 方法即可:

    FederatedAuthentication.WSFederationAuthenticationModule.SignOut("/MyPostSignoutRedirectUrl");
    

    【讨论】:

      【解决方案2】:

      要处理退出请求,请执行以下步骤:

      1. 点击退出链接后,清除联合cookie: System.Web.HttpContext.Current.Response.Cookies.Remove(stateKey);

      2. 使用 WS-Federation 退出参数作为操作将浏览器重定向到模拟颁发者:

      https://RelyingParty/SsoLogout.aspx?wa=wsignout1.0&wreply=...

      使用 WS-Federation 命令 — wa=wsignout1.0 退出发行人。

      1. 从 cookie 中检索 RP 列表并将注销清理命令发送到 他们每个人:
       https://RelyingParty1/SsoLogout.aspx?wa=wsignoutcleanup1.0,
      https://RelyingParty2/SsoLogout.aspx?wa= wsignoutcleanup1.0,
      https://RelyingParty3/SsoLogout.aspx?wa= wsignoutcleanup1.0

      这允许所有依赖方执行注销操作。

      它的工作原理如下:

      wa GET 参数中定义的 wsignout1.0 和 wsignoutcleanup1.0 操作 遵循 WS-Federation Passive Requestor 的依赖方很好理解 轮廓。这些操作允许从领域中的所有 RP 执行注销操作。

      【讨论】:

        【解决方案3】:

        如何将 cookie 更改为持久性 cookie 并在注销点击或会话结束时使 fedauth cookie 过期?

        RP 上的持久性 Cookie:

        <microsoft.identityModel>
              <federatedAuthentication>
                <wsFederation
                    persistentCookiesOnPassiveRedirects="true" />
                <cookieHandler 
                  persistentSessionLifetime="60.0:0:0" />
              </federatedAuthentication>
        </microsoft.identityModel>
        

        并让 Cookie 过期

            var c = Request.Cookies["FedAuth"];
            c.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(c);
        
            c = Request.Cookies["FedAuth1"];
            c.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(c);
        

        在此之后您将需要重定向。

        【讨论】:

          猜你喜欢
          • 2013-08-19
          • 2014-12-23
          • 2023-04-03
          • 2019-10-01
          • 1970-01-01
          • 2014-08-01
          • 2017-02-22
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多