Windows 通过 ADFS C#.NET Web Forms App 验证后出现验证框

Windows authentication box appears after authenticating through ADFS C#.NET Web Forms App

我最近更新了一个遗留的 4.5 C#.NET webforms 应用程序以使用 ADFS 进行身份验证,但不知何故它只有在我还在 IIS 中启用 Windows 身份验证时才有效。当我启用 windows 身份验证时,在用户登录我们的 ADFS 服务器后,会出现一个 Windows 身份验证弹出框,要求用户登录两次。这不是我想要的结果,所以我关闭了 Windows 身份验证,希望第二次登录会消失,但现在在登录 ADFS 后,用户收到 401 Unauthorized 错误。

如果我必须保持启用 Windows 身份验证才能让这个旧版应用程序成功登录,我是否应该在代码中添加一些内容以防止 Windows 身份验证弹出窗口在之后出现用户登录到 ADFS?

Startup.Auth.cs

public partial class Startup
{
    private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
    private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];

    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseWsFederationAuthentication(
            new WsFederationAuthenticationOptions
            {
                Wtrealm = realm,
                MetadataAddress = adfsMetadata
            });

        // This makes any middleware defined above this line run before the Authorization rule is applied in web.config
        app.UseStageMarker(PipelineStage.Authenticate);
    }
}

Startup.cs

public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
    }
}

更新:我刚刚确认我的开发站点工作正常 - 这意味着 Windows 身份验证框在使用 ADFS 进行身份验证后不会显示。它具有相同的代码、相同的 web.config、与实时相比在开发服务器上的 IIS 中的相同设置以及在 ADFS 服务器上的相同设置。我能看到的唯一区别是实时服务器是 Windows Server 2019 Datacenter 而开发服务器是 Windows Server 2012 R2.

这两个服务器之间是否存在差异,使得 Windows 身份验证框在 ADFS 身份验证后弹出?旧版应用程序是否只能在旧版服务器上运行,而不是新服务器?

我刚刚在这里找到了我需要的答案: 401 Unauthorized: Access is denied due to invalid credentials

  1. 打开 IIS
  2. Select 网站
  3. 开启认证
  4. 编辑匿名身份验证
  5. Select 应用程序池标识