Asp.Net核心页面中的LDAP身份验证错误

Asp.Net核心页面中的LDAP身份验证错误,ldap,razor-pages,asp.net-core-3.1,Ldap,Razor Pages,Asp.net Core 3.1,我已经使用System.DirectoryServices.AccountManagement包将LDAP集成到ASP.NET核心razor页面中 我遵循了他们在本文中使用的方法: 当我执行代码时,它将进入if条件,但不会重定向到主页 // set up domain context using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "mydomain.com")) { //

我已经使用
System.DirectoryServices.AccountManagement
包将LDAP集成到ASP.NET核心razor页面中

我遵循了他们在本文中使用的方法:

当我执行代码时,它将进入if条件,但不会重定向到主页

// set up domain context
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "mydomain.com"))
{
    // validate the user's credentials
    if (ctx.ValidateCredentials(userName, password)
    {
         return RedirectToPage("/Index");
    }
    else
    {
        ErrorMessage = "Invalid Username/Password";
        return Page();
    }
} 
当我调试时,它显示ValidateCredentials在当前上下文中不存在。我该如何解决这个问题?

请阅读-总结是,这不是一种理想的解决志愿者问题的方法,可能会对获得答案产生反作用。请不要将此添加到您的问题中。