Guest User

Untitled

a guest
Apr 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. public static DataTable getADValuesByParameter(string strFilter, string strLDAPUser, string strLDAPPath, string strLDAPPWD, string strLDAPProperties)
  2. {
  3. DataTable functionReturnValue = default(DataTable);
  4. string[] arrLDAP = null;
  5. DirectoryEntry rootEntry = new DirectoryEntry();
  6. DirectorySearcher searcher = new DirectorySearcher();
  7. SearchResultCollection results = default(SearchResultCollection);
  8. DataTable dtExchangeUserData = new DataTable();
  9. arrLDAP = strLDAPProperties.Split(new char[] { ',' });
  10. rootEntry.Path = strLDAPPath;
  11. rootEntry.Username = strLDAPUser;
  12. rootEntry.Password = strLDAPPWD;
  13. rootEntry.AuthenticationType = AuthenticationTypes.Secure;
  14.  
  15. searcher.SearchRoot = rootEntry;
  16. searcher.SearchScope = SearchScope.Subtree;
  17. searcher.Filter = strFilter;
  18. searcher.PropertiesToLoad.AddRange(arrLDAP);
  19.  
  20. //var value = rootEntry.NativeObject;
  21.  
  22. results = searcher.FindAll();
  23. Int16 si = default(Int16);
  24. foreach (SearchResult result in results)
  25. {
  26. si = 0;
  27. object[] arrKeyValue = new object[result.Properties.Count - 1];
  28. // -2 weil property "adspath" nicht dazu gehört, und .count -1 weil 0 basierendes array
  29. if ((result != null))
  30. {
  31. System.Collections.IEnumerator myEnumerator = arrLDAP.GetEnumerator();
  32. while (myEnumerator.MoveNext())
  33. {
  34. foreach (string Key in result.Properties.PropertyNames)
  35. {
  36. if (Key != "adspath")
  37. {
  38. if (Key.Equals(((string)myEnumerator.Current).ToLower()))
  39. {
  40. if (dtExchangeUserData.Columns[Key] == null)
  41. dtExchangeUserData.Columns.Add(Key);
  42. if (Key.Equals("objectguid"))
  43. {
  44. arrKeyValue[si] = new Guid(((byte[])result.Properties[Key][0]));
  45. }
  46. else
  47. {
  48. arrKeyValue[si] = result.Properties[Key][0].ToString();
  49. }
  50. si++;
  51. }
  52. }
  53. }
  54. }
  55. if (arrKeyValue.Length > 0)
  56. dtExchangeUserData.Rows.Add(arrKeyValue);
  57. }
  58. }
  59.  
  60. functionReturnValue = dtExchangeUserData;
  61. dtExchangeUserData.Dispose();
  62. rootEntry.Close();
  63. rootEntry.Dispose();
  64. return functionReturnValue;
  65. }
  66.  
  67. Membership.ValidateUser()
  68.  
  69. <connectionStrings>
  70. <add name="ADConnectionString" connectionString="LDAP://server.com/OU=users,DC=test,DC=adam"/>
  71. </connectionStrings>
  72. <authentication mode="Forms" >
  73. <forms loginUrl="~/Login.aspx/Test/" timeout="2880" />
  74. </authentication>
  75. <authorization>
  76. <deny users ="?" />
  77. </authorization>
  78.  
  79. <!--<identity impersonate="true" />-->
  80.  
  81. <trust level="Full" />
  82.  
  83. <membership defaultProvider="MyMembershipProvider">
  84. <providers>
  85. <add name="MyMembershipProvider"
  86. type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
  87. connectionStringName="ADConnectionString"
  88. connectionUsername="[domain][user]"
  89. connectionPassword="[password]"
  90. connectionProtection="Secure"
  91. enableSearchMethods="true"
  92. />
  93. </providers>
  94. </membership>
Add Comment
Please, Sign In to add comment