首页 > 解决方案 > Wsfederation 错误。令牌过期后,注册用户的注册表单不断弹出

问题描述

我已经按照这个文档WSf在 Asp.net 核心上成功实现了 WSFederation 。当 20 分钟的空闲时间过去后,应用程序通过调用 ADFS 页面重新进行身份验证。但是,应用程序会将注册用户带回注册页面。然后,我将回收应用程序池或重新启动网站以使其再次运行。我该如何解决这个问题?我的注册表. 控制台显示错误 401

标签: asp.net-corews-federation

解决方案


on start up
services.AddAuthentication()
.AddWsFederation(WsFederationDefaults.AuthenticationScheme, "Login Using Office Account",
options =>
{
   options.MetadataAddress = "https://xxxxxxxxxxxx/FederationMetadata/2007-
  06/FederationMetadata.xml";

    options.Wtrealm = "https://xxxxxxxxxxxx.org/";
}).AddCookie();

        services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath = "/Identity/Account/LogIn";
            }
        );
        services.ConfigureApplicationCookie(options => options.LogoutPath = "/Home/Index");
and on logout

//delete all cookies first
foreach (var key in HttpContext.Request.Cookies.Keys)
 {
    HttpContext.Response.Cookies.Delete(key);
 }

    await _signInManager.SignOutAsync();
    _logger.LogInformation("User logged out.");
     return SignOut(new AuthenticationProperties { RedirectUri = "/Home/Index" }, 
     CookieAuthenticationDefaults.AuthenticationScheme, 
     WsFederationDefaults.AuthenticationScheme);
    enter code here

The solution I found that works were to increase the application pool idle time from default 20 minutes to any minutes of choice. The user can then work and logout of the application without issues. You can also review the code I have and suggest some improvements if needed

推荐阅读