I need an urgent help in Active directory and LDAP.

ASP.net , Csharp , ActiveDirectory Gaborone, Botswana
  • 11 years ago

    I am facing a problem in my web application in the log in Page in ASP.net.The Problem is arising whenever i am authenticating my log in credentials using the LDAP to connect to Active directory in the server.I am giving you the code where the exception is getting thrown. public string[] GetIssuerFromActiveDirectory(string loginName) { try { string[] issuerDetails = new string[3]; string path = ConfigurationManager.AppSettings["LDAPPath"]; string groupName = null; String dn; DirectoryEntry entry = new DirectoryEntry(path); // Bind to the native AdsObject to force authentication.
    Object obj = entry.NativeObject; DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=" + loginName + ")"; SearchResult result = search.FindOne(); issuerDetails[0] = (String)result.Properties["name"][0]; issuerDetails[2] = (String)result.Properties["mail"][0];

                int propertyCount = result.Properties["memberOf"].Count;
                int equalsIndex, commaIndex;
    
                if (propertyCount <= 0)
                    issuerDetails[1] = null;
                else
                {
                    for (int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++)
                    {
                        dn = (String)result.Properties["memberOf"][propertyCounter];
                        equalsIndex = dn.IndexOf("=", 1);
                        commaIndex = dn.IndexOf(",", 1);
    
                        groupName = (dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1));
                        if (groupName.Equals(ConfigurationManager.AppSettings["AdminRole"]) || groupName.Equals(ConfigurationManager.AppSettings["MemberRole"]))
                        {
                            issuerDetails[1] = groupName;
                        }
                    }
                }
    
                return issuerDetails;
            }
            catch (CustomException cex)
            {
                throw cex;
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                CustomException cex = Exceptions.GetCustomException("issuer not present in active directory", ex);
                throw cex;
            }
        }
    

    its giving the exception at
    Object obj = entry.NativeObject; saying refferal was sent to the server. Can anyone help me with this exception.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry