简体   繁体   中英

Azure LDAP with DirectoryEntry “the server is not operational” error C#

I have configured secure LDAP in windows azure by using following tutorial:

https://azure.microsoft.com/en-us/documentation/articles/active-directory-ds-admin-guide-configure-secure-ldap/

But I am getting "the server is not operational" error. I am trying to use following code:

string DomainPath = "LDAP://0.0.0.0:636";
DirectoryEntry searchRoot = new DirectoryEntry(DomainPath, "someone@example.com", "password", AuthenticationTypes.Secure);
DirectorySearcher search = new DirectorySearcher(searchRoot);
search.Filter = "(&(objectClass=user)(objectCategory=person))";
search.PropertiesToLoad.Add("samaccountname");
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("usergroup");
search.PropertiesToLoad.Add("displayname");//first name
SearchResult result;
SearchResultCollection resultCol = search.FindAll();
if (resultCol != null)
{
   for (int counter = 0; counter < resultCol.Count; counter++)
   {
      string UserNameEmailString = string.Empty;
      result = resultCol[counter];
      if (result.Properties.Contains("samaccountname") && result.Properties.Contains("mail") &&
                                result.Properties.Contains("displayname"))
      {
          Users objSurveyUsers = new Users();
          objSurveyUsers.Email = (String)result.Properties["mail"][0] +
                                  "^" + (String)result.Properties["displayname"][0];
          objSurveyUsers.UserName = (String)result.Properties["samaccountname"][0];
          objSurveyUsers.DisplayName = (String)result.Properties["displayname"][0];
          lstADUsers.Add(objSurveyUsers);
      }
   }
}

I have also tried to connect my Ip and domain in ldp.exe software it is also giving error failed to connect.

My question is that can I use DirectoryEntry in azure platform to fetch users?

If not so what is the purpose of LDAP in Azure?

Thanks in Advance

On Azure, the way with best practice to fetch users from Azure AD is using Azure AD Graph API, please refer to the overview to know it.

There are two ways for using AAD Graph API which include REST & SDK .

As reference, there is an article introduced how to do the operations on users using Graph API and supply sample codes for different programming languages, please see https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM