在通过ADFS C#.NET Web Forms应用程序进行身份验证后,会出现Windows身份验证框。

8 浏览
0 Comments

在通过ADFS C#.NET Web Forms应用程序进行身份验证后,会出现Windows身份验证框。

最近,我将一个遗留的4.5版本的C#.NET WebForms应用程序更新,以便使用ADFS进行身份验证,但不知何故,只有在IIS中启用了Windows身份验证时才能正常工作。当我启用Windows身份验证后,用户在登录我们的ADFS服务器后会出现一个Windows身份验证弹出框,需要用户登录两次。这不是我想要的结果,因此我关闭了Windows身份验证,希望第二次登录会消失,但现在,在登录ADFS后,用户会收到401未经授权的错误。

如果我必须保持Windows身份验证对于这个遗留应用程序成功登录,那么在代码中是否应该添加一些内容来防止用户在登录ADFS后出现Windows身份验证弹出框呢?

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);
    }
}

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

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

0
0 Comments

Windows身份验证框在通过ADFS C#.NET Web Forms应用程序进行身份验证后出现的原因是由于匿名身份验证设置不正确。解决方法是通过以下步骤进行更改:

  1. 打开IIS
  2. 选择网站
  3. 打开身份验证
  4. 编辑匿名身份验证
  5. 选择应用程序池身份
0