To connect to an ldap -Server i want to use Directory Services in a c# -console application.
These are the steps to reproduce:
do.net new console -f.net5.0 -o=ConsoleFiveToSeven
cd ConsoleFiveToSeven
do.net run
ConsoleFiveToSeven.csproj
change <TargetFramework.net5.0</TargetFramework>
to <TargetFramework.net7.0</TargetFramework>
and savedo.net run
again. This creates \ConsoleFiveToSeven\bin\Debug.net7.0
do.net add package System.DirectoryServices.Protocols --version 7.0.0
do.net build
distinguishedName
and ldapFilter
and searchScope
and attributeList
does not exist in the current contextThe docs for SearchRequest contains this constructor
public SearchRequest (string distinguishedName
, string ldapFilter
, System.DirectoryServices.Protocols.SearchScope searchScope
, params string[] attributeList);
To my understanding the following code below should be fine. What is the problem?
using System;
using System.Net;
using System.DirectoryServices.Protocols;
namespace ConsoleFiveToSeven
{
class Program
{
static void Main(string[] args)
{
SearchRequest search = new SearchRequest(
distinguishedName = "foo",
ldapFilter = "foo",
searchScope = SearchScope.Subtree,
attributeList = new string [] {"cn=foo", "cn=bar", "cn=com"}
);
}
}
}
Not entirely. In C#, =
to specify parameters by names is invalid. You should use :
SearchRequest search = new SearchRequest(
distinguishedName: "foo",
ldapFilter: "foo",
searchScope: SearchScope.Subtree,
attributeList: new string [] {"cn=foo", "cn=bar", "cn=com"});
But if you use default order of parameters you can omit their names:
SearchRequest search = new SearchRequest(
"foo",
"foo",
SearchScope.Subtree,
new string [] {"cn=foo", "cn=bar", "cn=com"});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.