0

以下代码适用于域管理员。但不具有用户权限。

using System;
using System.Collections.Generic;
using System.DirectoryServices.AccountManagement;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinM
{
    class Program
    {
        static void Main(string[] args)
        {
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
        }
    }
}

如果我以用户身份运行它,我会收到以下错误:

Unhandled Exception: System.DirectoryServices.Protocols.LdapException: The connection cannot be established.
   at System.DirectoryServices.Protocols.ConnectionHandle..ctor(IntPtr value, Boolean disposeHandle)
   at System.DirectoryServices.Protocols.LdapConnection.Init()
   at System.DirectoryServices.Protocols.LdapConnection..ctor(LdapDirectoryIdentifier identifier, NetworkCredential credential, AuthType authType)
   at System.DirectoryServices.Protocols.LdapConnection..ctor(LdapDirectoryIdentifier identifier)
   at System.DirectoryServices.Protocols.LdapConnection..ctor(String server)
   at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
   at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
   at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType)
   at WinM.Program.Main(String[] args) in

有人有想法吗?

4

1 回答 1

0

同样的问题,直到我意识到 SMB 文件夹没有为收到 LdapException 的用户帐户共享。将用户添加到具有更改+读取权限的列表后,问题就解决了。

于 2020-08-11T16:05:05.003 回答