3

我正在使用 LDAP 连接类,从MSDN 上的这个页面开始工作。

我已经使用字符串构造函数实例化了该类,如下所示:

LdapConnection ld = new LdapConnection("LDAP://8.8.8.8:8888");

我现在想设置我的凭据,所以我正在尝试执行以下操作:

ld.Credential.UserName = "Foo";

但我收到以下错误:

无法在此上下文中使用属性或索引器“System.DirectoryServices.Protocols.DirectoryConnection.Credential”,因为它缺少 get 访问器。

但是,在键入此内容时,智能感知会显示以下内容:

在此处输入图像描述

这个描述表明 UserName 确实应该有一个 Get Accessor,我错过了什么?

谢谢

4

1 回答 1

6

The LdapConnection.Credential Property doesn't have a get accessor, so you can't retrieve its current value and set the UserName property on the returned NetworkCredential instance. You can only assign to the LdapConnection.Credential Property:

ld.Credential = new NetworkCredential(userName, password);

or

var credential = new NetworkCredential();
credential.UserName = userName;
credential.Password = password;
ld.Credential = credential;

or

ld.Credential = new NetworkCredential
{
    UserName = userName,
    Password = password,
};
于 2012-05-20T11:37:30.663 回答