C# script to connect to Oracle Directory Server Enterprise Edition

-1

I have a C# script I am trying to use to connect to an Oracle Directory Server Enterprise Edition So far i have had very little success. I am receiving a Unknown error (0x80005000) error message Can somebody tell me what I am doing wrong. I have been researching the web and most online boards say that this error message is because the LDAP in the path needs to be in uppercase letters. As you can see I have done that but still no luck.

Below is my code

 private static readonly string PATH = "LDAP://LDAPDEV.example.com:389/o=example.com";
 private static readonly string USERNAME = uid=SERVICE_USR,ou=ApplicationIDs,o=example.com";
 private static readonly string PASSWORD = "test1234";  


      string DN = "";

        // connect to determine proper distinguishedname
        DirectoryEntry Entry = new DirectoryEntry(Path, USERNAME, PASSWORD, AuthenticationTypes.None);

        try
        {
            // Bind to the native AdsObject to force authentication.
            Object obj = Entry.NativeObject;

            DirectorySearcher Search = new DirectorySearcher(Entry);
            Search.ReferralChasing = ReferralChasingOption.All
        }
        catch (Exception ex)
        {
            throw new Exception("Error looking up distinguishedname. ", ex);
        }
        finally
        {
            anonymousEntry.Close();
        }

        return DN;
    }

string sDomain="LDAPDEV.example.com:389"; 
string sDefaultOU = @"o=example.com"; 
string sServiceUser = @"uid=user,ou=ApplicationIDs,o=example.com"; 
string sServicePassword = "password"; 

try 
 {
PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, ontextOptions.SimpleBind, sServiceUser,sServicePassword); 

 } 
 catch (Exception ex) 
 {
          ex.Message; 
 }
c#
oracle
ldap
asked on Stack Overflow Sep 18, 2014 by user3852972 • edited Jul 7, 2019 by Cœur

1 Answer

0

Here is something that you can use to get some information by using PrincipalContext look at this working example and replace the values with your domain name values.

 // if you are doing this via web application if not you can replace
 // the Request/ServerVariables["LOGON_USER"] 
 // with Environment.UserName; this will return your user name like msmith for example so var userName = Environvironment.UserName; 
 var userName = Request.ServerVariables["LOGON_USER"].Split(new string[] {"\\"}, StringSplitOptions.RemoveEmptyEntries);
 var pc = new PrincipalContext(ContextType.Domain,"yourdomain.com",null, null);
 var userFind = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, userName);

this is basically all you need to see the information like email address SamAccountName ect.. use the debugger to inspect all the property values available in the pc variable and userFind variable

answered on Stack Overflow Sep 22, 2014 by MethodMan

User contributions licensed under CC BY-SA 3.0