Asp.net LDAP服务器不可用

Asp.net LDAP服务器不可用,asp.net,asp.net-mvc,ldap,Asp.net,Asp.net Mvc,Ldap,我在MVC中使用LDAP进行用户身份验证。我的代码如下所示: public ActionResult Login(LoginViewModel model, string returnUrl) { bool validation; try { LdapConnection ldc = new LdapConnection(new LdapDirec

我在MVC中使用LDAP进行用户身份验证。我的代码如下所示:

public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            bool validation;
                try
                {   
                    LdapConnection ldc = new LdapConnection(new LdapDirectoryIdentifier((string)null, false, false));
                    NetworkCredential nc = new NetworkCredential(model.UserName, model.Password, "XXXXXXX");
                    ldc.Credential = nc;
                    ldc.AuthType = AuthType.Negotiate;
                    ldc.Bind(nc); // user has authenticated at this point, as the credentials were used to login to the dc.
                    validation = true;
                    return RedirectToAction("Index", "Home");

                    //validation = true;
                }
                catch (LdapException)
                {
                    validation = false;
                }
                return View(model);
}
但我得到一个错误,因为“LDAP服务器不可用”

Web.Config:

<authentication mode="Forms">
              <forms loginUrl="~/Account/LogOn" timeout="10"/>
 </authentication>  
<membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
      <providers>
        <clear />
        <add name="AspNetActiveDirectoryMembershipProvider" 
             type="System.Web.Security.ActiveDirectoryMembershipProvider,System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             connectionStringName="ADConnectionString"
              attributeMapUsername="sAMAccountName"  />

      </providers>
</membership>
 <add name="ADConnectionString" connectionString="LDAP://XXXXXXX:389/DC=XXXX,DC=XXXX" />

您没有设置LDAP服务器的路径(当前为空)

要进行调试,请删除try..catch并查看错误的确切来源。您可能需要与网络管理员验证路径,或者使用任何工具,如查看路径和凭据是否有效


另外,请确保您想要验证的方式是正确的。如果这是一个intranet应用程序,那么您可能可以设置集成的Windows身份验证,它不需要任何自定义登录过程,并且可以在IIS上进行配置。

您可以使用任何标准的AD工具连接到LDAP服务器吗?我不知道这一点。您可以为此给我一些提示吗?尝试使用目录条目[或LDAPSoft][因为我对这个概念很陌生..你能给我提供一些关于这个的链接或教程,让我了解在MVCACTULAY中使用LDAP进行用户身份验证的方法吗?我不知道使用LDAP对用户进行身份验证的过程,对此我很困惑。你对此有什么基本的想法吗?你能提供一些示例代码吗如果您没有指定服务器,您将获得“LDAP服务器不可用”。您拥有的web.config文件与方法中的代码无关。如果查看代码,您将创建一个新的LdapConnection,但服务器名称在哪里?您将设置NULL而不是服务器的路径。阅读更多信息
LdapConnection ldc = new LdapConnection(
      new LdapDirectoryIdentifier((string)null, false, false)
);