Wsfederation错误。令牌过期后,注册表单会继续为注册用户弹出

时间:2019-03-09 06:41:56

标签: asp.net-core ws-federation

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

1 个答案:

答案 0 :(得分:0)

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