Phi*_*ipp 4 linux ldap .net-core
我正在开发一个基于 .net core (2.2.103) 的应用程序,它必须连接到 LDAP 服务器。在运行 Windows 的开发机器上,我使用了System.DirectoryServices
命名空间。但是,该应用程序必须在 Linux (Ubuntu) 上运行,并且我得到了一个PlatformNotSupportedException
,所以我添加了一个引用
<PackageReference Include="Novell.Directory.Ldap" Version="2.2.1" />
并使用了它。
不幸的是,PlatformNotSupportedException
当连接被处理时,这会引发另一个(但由于线程中止):
Unhandled Exception: System.PlatformNotSupportedException: Thread abort is not supported on this platform.
at System.Threading.Thread.Abort()
at Novell.Directory.Ldap.Connection.Dispose(Boolean disposing, String reason, Int32 semaphoreId, InterThreadException notifyUser)
at Novell.Directory.Ldap.Connection.destroyClone(Boolean apiCall)
at Novell.Directory.Ldap.LdapConnection.Finalize()
Run Code Online (Sandbox Code Playgroud)
Linux 上的 dotnet core 是否有可靠的 LDAP 实现?
Pan*_*vos 12
您尝试使用的包上次更新是在 2014 年。它既不符合 .NET Core 也不符合 .NET Standard。
您可以尝试使用Novell.Directory.Ldap.NETStandard。尽管名称如此,但这不是 Novell 库。NuGet 中还有其他 LDAP 库,但这似乎是最受欢迎的,并且仍在积极开发中。
例外情况表明您也忘记处理连接。Finalize
仅由垃圾收集器调用。
此答案显示了如何使用 Novell.Directory.Ldap.NETStandard 对用户进行身份验证:
public bool ValidateUser(string domainName, string username, string password)
{
string userDn = $"{username}@{domainName}";
try
{
using (var connection = new LdapConnection {SecureSocketLayer = false})
{
connection.Connect(domainName, LdapConnection.DEFAULT_PORT);
connection.Bind(userDn, password);
if (connection.Bound)
return true;
}
}
catch (LdapException ex)
{
// Log exception
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
连接是在using
块内创建的,以确保一旦执行离开块的范围,它就会被处理掉
Mir*_*mec 12
随着.NET 5的发布,Microsoft 为库System.DirectoryServices.Protocols添加了跨平台支持(windows、linux、macos)。System.DirectoryServices
它是建立在低级 LDAP API之上的。我希望他们System.DirectoryServices
将来也能跨平台。
来源:.NET 5 - 将directoryservices.protocols扩展到linux和macos
我个人仍然使用Novell.Directory.Ldap.NETStandard,但我对此并不满意。我希望我能找到一些时间并尽快切换到system.directoryservices.protocols
甚至更好的system.directoryservices
图书馆。
归档时间: |
|
查看次数: |
8874 次 |
最近记录: |