【问题标题】:Ldap - the network path was not foundldap - 未找到网络路径
【发布时间】:2019-01-24 05:06:06
【问题描述】:

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

代码在本地PC上运行正常,我部署后仅在windows服务器出现错误。

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

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

这是一个 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;
}

【问题讨论】:

  • @Am_I_Helpful 是的,它是 sAMAccountName。如果我不附加 userId,它怎么知道我在寻找哪个用户?

标签: c# ldap


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多