LDAP-找不到网络路径

时间:2018-08-17 07:43:44

标签: c# ldap

尝试在LDAP中搜索用户时遇到以下错误。

该代码在本地PC上可以正常运行,并且仅在我部署Windows Server后才发生错误。

  

2018-08-17 15:29:21.190 +08:00 [错误]为lsun获取全名时出错
  System.DirectoryServices.DirectoryServicesCOMException(0x80070035):找不到网络路径。

     

在System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)
  在System.DirectoryServices.DirectoryEntry.Bind()
  在System.DirectoryServices.DirectoryEntry.get_AdsObject()
  在System.DirectoryServices.PropertyValueCollection.PopulateList()
  在System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry条目,字符串propertyName)中
  在System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
  在C:\ Code \ Project \ branches \ test \ src \ DotNet \ Company.Project.Common \ Utility \ LDAPUtility.cs:line 344中的Company.Project.Common.Utility.LDAPUtility.QueryLDAPUserFullName(String userId)   在C:\ Code \ Project \ branches \ test \ src \ DotNet \ Company.Project.Common \ Utility \ LDAPUtility.cs:line 239

中的Company.Project.Common.Utility.LDAPUtility.GetUserFullName(String userId)

这是Windows服务应用程序,这是引发错误的代码:

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;
}

1 个答案:

答案 0 :(得分:1)

我通过将Windows服务登录从“本地服务”更改为“网络服务”来解决此问题。在我看来,本地服务没有特权连接到LDAP。

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

相关问题