简体   繁体   中英

Ldap - the network path was not found

I encountered below error when trying to search users in LDAP.

The code runs ok at local PC and error occurs only at windows server after I deployed it.

2018-08-17 15:29:21.190 +08:00 [Error] Error in getting fullname for lsun
System.DirectoryServices.DirectoryServicesCOMException (0x80070035): The network path was not found.

at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
at Company.Project.Common.Utility.LDAPUtility.QueryLDAPUserFullName(String userId) in C:\\Code\\Project\\branches\\test\\src\\DotNet\\Company.Project.Common\\Utility\\LDAPUtility.cs:line 344
at Company.Project.Common.Utility.LDAPUtility.GetUserFullName(String userId) in C:\\Code\\Project\\branches\\test\\src\\DotNet\\Company.Project.Common\\Utility\\LDAPUtility.cs:line 239

This is a Windows service application and this is the code throwing the error:

private static string QueryLDAPUserFullName(string userId)
{
    string fullName = "";

    DirectoryEntry objDirEnt = new DirectoryEntry(ConstPrivileges.ADSPROVIDER + "://" + ConstPrivileges.DOMAIN + "/" + userId);

    if (objDirEnt.Children != null)
        fullName = objDirEnt.Properties["FullName"].Value.ToString();//Line 344

    return fullName;
}

I fixed this issue by changing the windows service logon from 'Local Service' to 'Network Service'. It seems to me that Local Service does not have privilege to connect to LDAP.

The difference between the 'Local System' account and the 'Network Service' account?

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