locked
Getting LdapException: Unable to connect to server :389 (91) Connect Error System.IO.IOException RRS feed

  • Question

  • User-1225773522 posted

    Hi All,

    We have asp.net core 2.1 web application and for user authentication we are using AD (LDAP auth) and referring Novell.Directory.Ldap.NETStandard2_0 library.

    So far, we are able to connect with our active directory and able to fetch the logged-in user details.

    But getting exception while returning the user details at below code.

    public override async Task<SignInResult> PasswordSignInAsync(string userName, string password, bool rememberMe, bool lockOutOnFailure)
            {
                var user = await this.UserManager.FindByNameAsync(userName);
    
                if (user == null)
                {
                    return SignInResult.Failed;
                }
    
                return await this.PasswordSignInAsync(user, password, rememberMe, lockOutOnFailure);
            }

    The exception is ----------------
    {LdapException: Unable to connect to server xyz.com:389 (91) Connect Error
    System.IO.IOException: Unable to transfer data on the transport connection: 
    An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException:
    An existing connection was forcibly closed by the remote host --- End of inner exception stack trace ---at
    Novell.Directory.Ldap.AsyncExtensions.WaitAndUnwrap(Task task, Int32 timeout) at Novell.Directory.Ldap.Connection.connect(String host, Int32 port, Int32 semaphoreId)} PasswordSignInAsync+Connect Error System.IO.IOException+Novell.Directory.Ldap

    Could you please point why we are getting this exception.

    Saturday, October 20, 2018 6:24 AM

Answers

  • User-1225773522 posted

    Hi Yu,

    Yes I referred the same link. The issue is resolved now, it was because of property SecureSocketLayer was true, i changed to false.

    public bool Authenticate(string distinguishedName, string password)
            {
                using (var ldapConnection = new LdapConnection() { SecureSocketLayer = true })
                {
                    ldapConnection.Connect(this._ldapSettings.ServerName, this._ldapSettings.ServerPort);
    
                    try
                    {
                        ldapConnection.Bind(distinguishedName, password);
    
                        return true;
                    }
                    catch (Exception)
                    {
                        return false;
                    }
                }
            }     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 27, 2018 5:22 AM

All replies

  • User1724605321 posted

    Hi sonu888,

    You can refer to below link for code sample about authenticating against Active Directory with ASP.Net Core 2 and managing users using Novell:

    https://www.brechtbaekelandt.net/blog/post/authenticating-against-active-directory-with-aspnet-core-2-and-managing-users 

    That error usually means that the target machine is running, but the service that you're trying to connect to is not available. The connection to the machine (remote host/server/PC that the service runs at) was made but, since the service was not available on that machine, the machine does not know how to process the request.

    The cause is when the service/object you are monitoring has stopped, crashed, or is busy with another request. Please check that .

    Best Regards,

    Nan Yu

    Monday, October 22, 2018 6:43 AM
  • User-1225773522 posted

    Hi Yu,

    Yes I referred the same link. The issue is resolved now, it was because of property SecureSocketLayer was true, i changed to false.

    public bool Authenticate(string distinguishedName, string password)
            {
                using (var ldapConnection = new LdapConnection() { SecureSocketLayer = true })
                {
                    ldapConnection.Connect(this._ldapSettings.ServerName, this._ldapSettings.ServerPort);
    
                    try
                    {
                        ldapConnection.Bind(distinguishedName, password);
    
                        return true;
                    }
                    catch (Exception)
                    {
                        return false;
                    }
                }
            }     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 27, 2018 5:22 AM