C# 使用c从ADFS注销#
我使用ADFS创建了一个asp.net Web表单应用程序。使用模板附带的默认方法,登录和注销可以完美地工作 例如,模板中包含的签出按钮方法C# 使用c从ADFS注销#,c#,asp.net,webforms,adfs,C#,Asp.net,Webforms,Adfs,我使用ADFS创建了一个asp.net Web表单应用程序。使用模板附带的默认方法,登录和注销可以完美地工作 例如,模板中包含的签出按钮方法 protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e) { // Redirect to ~/Account/SignOut after signing out. string callbackUrl =
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);
}
我已经设置了一个计时器,当达到零时,我尝试使用上面的代码注销用户,但它不起作用。没有抛出错误
有没有关于如何在此处执行注销的建议?您是否尝试过上面的代码,这些代码是您在没有计时器的情况下直接发布的?它起作用了吗 另外,尝试实现下面的代码,看看它是否有效
public void LogOut()
{
var module = FederatedAuthentication.WSFederationAuthenticationModule;
module.SignOut(false);
var request = new SignOutRequestMessage(new Uri(module.Issuer), module.Realm);
Response.Redirect(request.WriteQueryString());
}
对我来说,有效的方法是在超时时调用隐藏按钮的click事件,这反过来会导致下面的代码运行
// 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);
ADFS是负责验证用户和管理用户会话的服务器。网站/表单正在使用此服务。使用此服务的站点不能完全控制它,这是有道理的。对我来说,从ADFS服务器注销用户并让该服务器为您完成繁重的工作会更有意义 请注意,ADFS服务器让用户登录到ADFS服务器,并且请注意,当用户请求访问资源时,这会显示在访问令牌中。它们是不同的东西。通常,当使用identity server等产品注销某人时,为了注销,您需要做两件事:
- 撤消访问令牌
- 在身份验证服务器上注销(如果 这是需要的,有人可能会说这是不需要的)
希望这有帮助。模块返回空值。我得到错误:对象引用未设置为对象的实例。