[英]How to upgrade a Console app from .net 5 to .net 7 to use DirectoryServices
要連接到ldap服務器,我想在c# 控制台應用程序中使用目錄服務。
這些是重現的步驟:
do.net new console -f.net5.0 -o=ConsoleFiveToSeven
cd ConsoleFiveToSeven
do.net run
ConsoleFiveToSeven.csproj
<TargetFramework.net5.0</TargetFramework>
更改為<TargetFramework.net7.0</TargetFramework>
並保存do.net run
。 這將創建\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 contextSearchRequest的文檔包含此構造函數
public SearchRequest (string distinguishedName
, string ldapFilter
, System.DirectoryServices.Protocols.SearchScope searchScope
, params string[] attributeList);
據我了解,下面的代碼應該沒問題。 問題是什么?
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"}
);
}
}
}
不是完全。 在 C# 中, =
以名稱指定參數是無效的。 你應該使用:
SearchRequest search = new SearchRequest(
distinguishedName: "foo",
ldapFilter: "foo",
searchScope: SearchScope.Subtree,
attributeList: new string [] {"cn=foo", "cn=bar", "cn=com"});
但是如果你使用參數的默認順序,你可以省略它們的名字:
SearchRequest search = new SearchRequest(
"foo",
"foo",
SearchScope.Subtree,
new string [] {"cn=foo", "cn=bar", "cn=com"});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.