首页 > 解决方案 > 使用 c# 从 ADFS 注销

问题描述

我使用 ADFS 创建了一个 asp.net webform 应用程序。使用模板附带的默认方法登录和注销工作完美。

例如,模板中包含的注销按钮方法

protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e)
        {
            // Redirect to ~/Account/SignOut after signing out.
            string callbackUrl = Request.Url.GetLeftPart(UriPartial.Authority) + Response.ApplyAppPathModifier("~/Account/SignOut");

            HttpContext.Current.GetOwinContext().Authentication.SignOut(
                new AuthenticationProperties { RedirectUri = callbackUrl },
                WsFederationAuthenticationDefaults.AuthenticationType,
                CookieAuthenticationDefaults.AuthenticationType);
        }

我已经设置了一个计时器,当达到零时,我尝试使用上面的代码将用户注销,但它不起作用。没有抛出错误。

任何建议如何在这里执行注销?

标签: c#asp.netwebformsadfs

解决方案


您是否尝试过没有计时器直接发布的上述代码?它起作用了吗?

另外,尝试实现下面的代码,看看它是否有效。

 public void LogOut()
{          
    var module = FederatedAuthentication.WSFederationAuthenticationModule;
    module.SignOut(false);
    var request = new SignOutRequestMessage(new Uri(module.Issuer), module.Realm);
    Response.Redirect(request.WriteQueryString());
}

推荐阅读