Novell.Directory.Ldap.LdapConnection.Connect C# (CSharp) 메소드

Connect() 공개 메소드

Connects to the specified host and port. If this LdapConnection object represents an open connection, the connection is closed first before the new connection is opened. At this point, there is no authentication, and any operations are conducted as an anonymous client. When more than one host name is specified, each host is contacted in turn until a connection can be established.
LdapException A general exception which includes an error /// message and an Ldap error code. /// ///
public Connect ( System host, int port ) : void
host System A host name or a dotted string representing the IP address /// of a host running an Ldap server. It may also /// contain a list of host names, space-delimited. Each host /// name can include a trailing colon and port number. /// ///
port int The TCP or UDP port number to connect to or contact. /// The default Ldap port is 389. The port parameter is /// ignored for any host hame which includes a colon and /// port number. /// ///
리턴 void
        public virtual void Connect(System.String host, int port)
        {
            // connect doesn't affect other clones
            // If not a clone, destroys old connection.
            // Step through the space-delimited list
            SupportClass.Tokenizer hostList = new SupportClass.Tokenizer(host, " ");
            System.String address = null;

            int specifiedPort;
            int colonIndex; //after the colon is the port
            while (hostList.HasMoreTokens())
            {
                try
                {
                    specifiedPort = port;
                    address = hostList.NextToken();
                    colonIndex = address.IndexOf((System.Char) ':');
                    if (colonIndex != - 1 && colonIndex + 1 != address.Length)
                    {
                        //parse Port out of address
                        try
                        {
                            specifiedPort = System.Int32.Parse(address.Substring(colonIndex + 1));
                            address = address.Substring(0, (colonIndex) - (0));
                        }
                        catch (System.Exception e)
                        {
                            throw new System.ArgumentException(ExceptionMessages.INVALID_ADDRESS);
                        }
                    }
                    // This may return a different conn object
                    // Disassociate this clone with the underlying connection.
                    conn = conn.destroyClone(true);
                    conn.connect(address, specifiedPort);
                    break;
                }
                catch (LdapException LE)
                {
                    if (!hostList.HasMoreTokens())
                        throw LE;
                }
            }
            return ;
        }

Usage Example

예제 #1
1
        public bool CheckUser(string UserName, string OldPassword)
        {
            bool   result = true;
            string User   = UserName;
            string Pass   = OldPassword;

            // Creating an LdapConnection instance
            Novell.Directory.Ldap.LdapConnection ldapConn = new Novell.Directory.Ldap.LdapConnection();

            string dn = "uid = " + UserName + ",ou=users,dc=example,dc=com";

            try
            {
                //Connect function will create a socket connection to the server
                ldapConn.Connect(ldapHost, ldapPort);

                //Bind function will Bind the user object Credentials to the Server
                ldapConn.Bind(dn, OldPassword);
            }

            catch (Novell.Directory.Ldap.LdapException e)
            {
                TempData["msg"] = "<script>alert('Could not authenticate user!');</script>";
                result          = false;
                return(result);
            }

            finally
            {
                // Disconnect from LDAP
                ldapConn.Disconnect();
            }

            return(result);
        }
All Usage Examples Of Novell.Directory.Ldap.LdapConnection::Connect