ACS注销重定向无法正常工作

时间:2013-08-23 22:21:39

标签: c# single-sign-on acs

使用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和一个javascript调用来设置window.location,在将用户转移到另一个页面时似乎没有任何好转。我错过了什么?

1 个答案:

答案 0 :(得分: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);
    }