2014-09-18 63 views
-1

我有一個c#腳本,我試圖用它連接到Oracle Directory Server企業版 到目前爲止,我的成功很少。 我收到未知錯誤(0x80005000)錯誤消息 有人可以告訴我我做錯了什麼。我一直在研究網絡,大多數在線董事會都說這個錯誤信息是因爲路徑中的LDAP需要使用大寫字母。你可以看到我已經做到了,但仍然沒有運氣。連接到Oracle Directory Server Enterprise Edition的C#腳本

下面是我的代碼

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; 


    } 
enter code here 

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; 
} 
+0

連接字符串看起來是有點你讀過任何關於如何使用C#與'LDAP'或'Active Directory格式化連接字符串的文檔這裏是一個可用作示例的stackoverflow發佈http://stackoverflow.com/questions/15157746/connection- string-to-connect-to-active-directory-using-ldap在你的最後做了更多的研究,謝謝 – MethodMan 2014-09-18 15:46:26

+0

感謝你的迴應。你讀過我的問題了嗎?看來你指出我的帖子是指AD連接。怎麼樣非AD連接,這是我正在研究。當我按照指示,我仍然收到錯誤DirectoryEntry entry = new DirectoryEntry(「LDAP://地址/ DC =示例,DC = com」,「用戶名」,「passwd」);我收到的錯誤是「一個無效的DN語法已被指定」任何幫助,你可以非常感謝 – user3852972 2014-09-19 15:33:25

+0

嘗試改變你的代碼,並使用'PrincipalContext'這是非常容易.. http://stackoverflow.com/questions/11561689/ using-c-sharp-to-authenticate-user-against-ldap – MethodMan 2014-09-19 15:52:26

回答

0

這裏是東西,你可以用用PrincipalContext看看這個工作實例,並與您的域名值替換值來獲得一些信息。

// 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); 

這基本上是所有你需要看到這樣的電子郵件地址SAM帳戶等..信息使用調試器來檢查在pc變量的所有可用的屬性值和userFind可變