Tôi đang cố sử dụng thư viện .NET System.DirectoryServices.AccountManagement
để lấy UserPrincipal cho một người dùng Active Directory cụ thể.UserPrincipal.FindByIdentity Permissions
Tôi đã có đoạn mã sau:
PrincipalContext context = new PrincipalContext(ContextType.Domain, "DomainName");
userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);
Mã này được chạy như một người sử dụng tên miền hợp lệ, nhưng khi tôi thực hiện nó tôi nhận được ngoại lệ sau đây:
System.DirectoryServices. DirectoryServicesCOMException (0x8007052E): Lỗi đăng nhập: tên người dùng không rõ hoặc mật khẩu không đúng.
Điều thú vị là tôi có thể thực hiện cuộc gọi sau đây, sử dụng bối cảnh tương tự, mà không có một vấn đề:
context.ValidateCredentials(username, password, ContextOptions.Negotiate)
Ý tưởng?
Kiểm tra câu trả lời này: http://stackoverflow.com/questions/1863801/findbyidentity-failing-with-pricipaloperationexception-in-asp-net-webapp/3515280#3515280 –