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?
User contributions licensed under CC BY-SA 3.0