如何强制 LDAP 在 .NET 中使用辅助本地 IP 地址?
我需要访问防火墙后面的远程 LDAP 服务器(使用 C#/.NET)进行用户身份验证。
远程站点的防火墙设置为允许特定的 IP 地址,但它不是服务器上的主 IP 地址,即默认情况下,到远程 LDAP 服务器的连接将使用主 IP。
如何强制 LDAP 在 .NET 中使用辅助 IP 地址?
我专门使用 System.DirectoryServices.DirectoryEntry
和 System.DirectoryServices.AccountManagement.PrincipalContext
类,但我没有看到明显的方法来控制本地端点。
这就是我使用 TcpClient 绑定到本地 IP 地址的方式:
using System.Net;
using System.Net.Sockets;
IPEndPoint localEndpoint = ...get relevant local ip address that needs to connect
TcpClient tcp = new TcpClient( localEndpoint );
...do stuff with tcp client
注意:在这种情况下无法更改服务器的主 IP 地址。
PS:当我使用“绑定”一词时" 这里表示绑定到本地端点,LDAP 使用“绑定”一词来连接/验证目录。
I need to access a remote LDAP server behind a firewall (using C#/.NET) for user authentication.
The firewall at the remote site is set to allow a specific IP address, but it is not the primary IP Address on the server i.e. by default, the connection to the remote LDAP server would use the primary IP.
How do you force LDAP to use a secondary IP Address in .NET?
I am specifically using the System.DirectoryServices.DirectoryEntry
and System.DirectoryServices.AccountManagement.PrincipalContext
classes, but there isn't obvious way I could see to control the local end point.
This is how I would bind to a local IP address using a TcpClient:
using System.Net;
using System.Net.Sockets;
IPEndPoint localEndpoint = ...get relevant local ip address that needs to connect
TcpClient tcp = new TcpClient( localEndpoint );
...do stuff with tcp client
NB: The primary IP address of the server cannot be changed in this instance.
PS: While I use the word "bind" here to mean binding to a local end point, LDAP uses the word "bind" for connecting/authenticating to the directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须 PInvoke wldap32.dll 中的 ldap_* 函数。它看起来像 中的 LDAP_OPT_SOCKET_BIND_ADDRESSES 选项会话选项将让您控制要使用的本地端点。 System.DirectoryServices.Protocols 是此 API 的托管版本,但我在 LdapSessionOptions。
这对我有用:
示例用法:
You'll have to PInvoke the ldap_* functions in wldap32.dll. It looks like the LDAP_OPT_SOCKET_BIND_ADDRESSES option in Session Options will let you control which local endpoint to use. The System.DirectoryServices.Protocols is the managed version of this API, but I don't see a corresponding property in LdapSessionOptions.
This works for me:
Example usage: