开发者

Got Error while accessing Active Directory from Web Service on Production Server

开发者 https://www.devze.com 2023-02-14 20:29 出处:网络
I got the following error message to connect to the Active Directory to get the User Info through web service.

I got the following error message to connect to the Active Directory to get the User Info through web service.

The specified domain either does not exist or could not be contacted.

However, if I run the webservice locally, it is ok and I could get the user info from the web service.

If I run the following codes in normal way (not webservice), it's working fine. The problem only occurs if I changed it to the Web Service. Any advice? Thanks.

[WebMethod]
public string[] GetADUserInfo(string SAMAccount)
{    
        DirectoryEntry entry = new DirectoryEntry("LDAP://xxxx", "username", "pwd");

        try
        {
            string Filter = String.Format("(&(objectClass=user)(sAMAccountName={0}))", SAMAccount);

            string[开发者_JAVA技巧] properties = new string[] { "employeeid", "cn" };
            DirectorySearcher Dsearch = new DirectorySearcher(entry, Filter, properties);

            SearchResult result = Dsearch.FindOne();

            xxxxxxx
            xxxxxxx
        }
        catch (Exception ex)
        {
            Debug.Write("Err in GetADUserInfo : " + ex.Message);
        }


    return {"a","b"};
}


I just found out the answer. Previously, My LDAP String is LDAP://DC=aa,DC=bb,DC=cc

Instead of that, I changed it to use the Domain name and it becomes like the following:

LDAP://mydomain.com/DC=aa,DC=bb,DC=cc

I am not sure it is the correct way or not. But it works for me. Suggestions and Advices are welcome.

0

精彩评论

暂无评论...
验证码 换一张
取 消