0

在 ACS SSO 上工作,并且注销过程运行良好。问题是用户仍然在调用注销操作的同一页面上,无论我将其设置为重定向到什么

public ActionResult Logout()
{
    //Load identity configuration
    FederationConfiguration config = FederatedAuthentication.FederationConfiguration;

    //Get wtrealm from WSFederationConfiguration Section
    string wtrealm = config.WsFederationConfiguration.Realm;
    string wreply = wtrealm;

    //Read ACS Ws-Federation endpoint from web.config
    string wsFederationEndpoint = ConfigurationManager.AppSettings["ida:Issuer"];

    SignOutRequestMessage signoutRequestMessage = new SignOutRequestMessage(new Uri(wsFederationEndpoint));
    signoutRequestMessage.Parameters.Add("wreply", wreply);
    signoutRequestMessage.Parameters.Add("wtrealm", wtrealm);
    string signoutUrl = signoutRequestMessage.WriteQueryString();

    FederatedAuthentication.WSFederationAuthenticationModule.SignOut();
    return this.Redirect(signoutUrl);           
}

为了执行这个动作,页面有一个点击处理程序

$('#logout').click(function () {
    $.post('@Url.Action("Logout", "Home", new { area = "" })');
});

正确处理了单击,调用并执行了注销操作,但站点仍保留在调用页面上。网络日志显示了注销调用,但没有证据表明甚至尝试了重定向。为了调试,我注释掉了重定向到 signoutURL 并尝试了 RedirectToAction、RedirectToRoute 和设置 window.location 的 javascript 调用,但在将用户转移到不同页面方面似乎没有更好的方法。我错过了什么?

4

1 回答 1

0

我最终做的是将 Logout 逻辑移到 Model 类中

public class LogoutHandler
{
    public string Signout()
    {
        // Load Identity Configuration
        FederationConfiguration config = FederatedAuthentication.FederationConfiguration;

        // Get wtrealm from WsFederationConfiguation Section
        string wtrealm = config.WsFederationConfiguration.Realm;
        string wreply;
        wreply = wtrealm;

        // Read the ACS Ws-Federation endpoint from web.Config
        string wsFederationEndpoint = ConfigurationManager.AppSettings["ida:Issuer"];

        SignOutRequestMessage signoutRequestMessage = new SignOutRequestMessage(new Uri(wsFederationEndpoint));

        signoutRequestMessage.Parameters.Add("wreply", wreply);
        signoutRequestMessage.Parameters.Add("wtrealm", wtrealm);

        FederatedAuthentication.SessionAuthenticationModule.SignOut();

        return signoutRequestMessage.WriteQueryString();            
    }
}

并让我的注销操作调用该类以返回 URL,然后重定向到它。那时一切都很好,虽然我不知道移动设备是否有什么需要考虑的

    public ActionResult Logout()
    {
        string signoutUrl = new LogoutHandler().Signout();
        return Redirect(signoutUrl);
    }
于 2013-12-18T19:45:36.470 回答