C#을 사용한 Active Directory

PHPz
풀어 주다: 2024-09-03 15:33:36
원래의
496명이 탐색했습니다.

C#을 사용한 Active Directory는 컴퓨터, 회사 사용자 등을 구성하는 데 가장 먼저 사용됩니다. 가장 중요한 것은 일반적으로 기업 네트워크 및 비즈니스 목적으로 사용되는 사용자 관리 시스템입니다. 회사 관리자는 네트워크에 속한 컴퓨터, 프로필 및 액세스 권한 등에서 회사의 전체 기록을 구성하는 데 사용됩니다. Active Directory는 Oracle 및 SQL과 같은 데이터베이스 유형으로, 자체 쿼리 유형 언어와 LDAP 기반 규칙 집합을 가지고 있습니다.

구문:

DirectoryEntry 개체에 액세스하려면 Active Directory 사용자 이름, 비밀번호 및 서버 주소가 필요했습니다. 서버 주소에는 IP 주소가 포함되어 있거나 LDAP의 경로는 다음과 같은 구문과 같습니다.

LDAP://domain_name.com/DC=domain_name,DC=com
로그인 후 복사

C#에서 Active Directory는 어떻게 작동하나요?

Active Directory는 회사 사용자, 데스크톱 등을 구성하는 데 도움이 되는 IT 관리자에게 큰 도움이 됩니다. 전체 계층 구조는 어떤 네트워크에 속하고 프로필 사진에 표시되는 내용, 저장소에 액세스하는 사람 등을 포함합니다. 대부분의 기업은 데스크톱에서 양식 기반 LDAP 인증을 보유한 웹 애플리케이션으로 애플리케이션을 진행합니다. 경우에 따라 .NET 응용 프로그램은 Microsoft Active Directory(AD)와 상호 작용하여 사용자 목록을 검색하고, 그룹을 검색하고, 사용자를 인증하고, 어떤 사용자가 어느 Active Directory 그룹에 있는지 확인합니다. 몇 가지 접근 방식을 사용하면 도메인 내의 AD 데이터베이스에서 정보를 검색할 수 있습니다.

System.DirectoryServices 네임스페이스에 속하는 DirectoryEntry 및 DirectorySearch 클래스를 포함하는 LDAP(Lightweight Directory Access Protocol)를 사용하는 다양한 접근 방식이 있습니다. 또 다른 접근 방식은 System.DirectoryServices.AccountManagement 네임스페이스 아래 AD(Active Directory)의 전체 클래스 래퍼 집합을 활용하는 것입니다. LDAP 쿼리를 사용하면 AD 데이터베이스에서 정보를 얻을 수 있습니다. 이 클래스를 사용하면 전체 AD에 액세스할 수 있지만 래퍼 클래스를 사용하면 AD의 사용자, 컴퓨터 개체, 그룹을 검색할 수 있습니다. DirectoryEntry 및 DirectorySearch 개체 클래스는 System.DirectoryServices.AccountManagement.

개체보다 빠릅니다.

C#을 사용하는 Active Directory의 기본 사항에는 System.DirectoryService 라이브러리가 포함되어 있으며 AD 라이브러리 루틴으로 쿼리하는 데 도움이 됩니다. Active Directory는 DirectoryEntry 개체를 통해 통신합니다. 이러한 개체는 추가 개체 및 폴더를 쿼리할 수 있는 LDAP 데이터베이스에 대한 가장 중요한 연결입니다. DirectoryEntry 개체에 액세스하려면 Active Directory 사용자 이름, 비밀번호 및 서버 주소가 필요했습니다. 서버 주소에는 IP 주소가 포함되어 있거나 LDAP의 경로는 다음과 같습니다.

LDAP://domain_name.com/DC=domain_name,DC=com

C#을 사용한 Active Directory의 예

DirectoryEntry 개체에 대해 Active Directory에 연결하려면 Active Directory에 대한 보안 인증 연결을 나타내는 보안 인증 유형의 사용자를 생성해야 하기 때문입니다. 관리자 계정으로 연결하면 새 사용자 생성, 사용자 업데이트, 사용자 삭제 등과 같은 관리자 Active Directory 기능을 수행할 수 있습니다.

디렉토리 객체의 DirectoryEntry 가져오기

private DirectoryEntry Reterieve_DirectoryObject( )
{
DirectoryEntry Obj_de;
Obj_de=new DirectoryEntry("LDAP://IP_Address", "admin","password", AuthenticationTypes Secure);
return _de;
}
로그인 후 복사

C#의 Active Directory에서 사용자 가져오기

Active Directory에 연결되면 아래와 같이 사용자 가져오기와 같은 개체를 쿼리해야 합니다.

private DirectoryEntry Reterieve_User(string User_Name)
{
DirectoryEntry obj_de = Reterieve_DirectoryObject( );
DirectorySearcher obj_deSearch = new DirectorySearcher();
obj_deSearch.SearchRoot = obj_de;
obj_deSearch.Filter = "(&(objectClass=user)(JOHNAccountName=" + User_Name + "))";
obj_deSearch.SearchScope = SearchScope.Subtree;
SearchResult getPath = obj_deSearch.FindOne();
if (!(getPath == null))
{
obj_de = new DirectoryEntry(getPath.Path, "administrator", "password", AuthenticationTypes.Secure);
return obj_de;
}
else
{
return null;
}
}
로그인 후 복사

위 코드는 로그인 자격 증명에 따라 Active Directory에서 사용자를 검색하는 방법을 설명합니다. Active Directory와 마찬가지로 "JohnAccountName"과 같은 이름과 사용자 이름이 포함된 괄호 안에 포함된 특정 Active Directory 쿼리 언어를 사용해야 합니다. 결과에 연결되는 새 DirectoryEntry 개체 코드 옆에 있는 DirectoryEntry를 찾고 연결에서 관리자의 로그인 세부 정보를 사용합니다.

인증 사용자 생성

Active Directory에 대해 인증된 사용자를 생성하려면 유효한 LDAP 경로 문자열을 DirectoryEntry 클래스 생성자에 전달해야 하며 이는 LDAP://Doamin_name 형식을 따릅니다. 다음 방법을 살펴보겠습니다.

private bool AuthenticateUser(string domain_name, string user_name, string password)
{
bool result = false;
try
{
DirectoryEntry obj_de = new DirectoryEntry("LDAP://" + domainName, userName, password);
DirectorySearcher obj_dsearch = new DirectorySearcher(obj_de);
SearchResult _sResult = null;
sResult = obj_dsearch.FindOne();
result = true;
}
catch
{
result = false;
}
return result;
}
로그인 후 복사

C#에서 Active Directory의 사용자 세부 정보 변경

C#에서 Active Directory 개체의 속성을 변경하는 것은 C#에서 간단합니다. 먼저 DirectoryEntry 속성 필드에 액세스하고 그 전에 필요에 따라 값을 변경하여 null인지 아닌지 확인한 다음 마지막으로 함수를 호출합니다. 완료된 변경 사항을 실행하고 저장하는 ComminChanges입니다. 사용자의 이름 속성을 변경하는 것을 보여주는 아래 코드를 살펴보겠습니다.

DirectoryEntry obj_de = Reterieve_User ("smith.rio");
if (obj_de!= null)
{
if (obj_de.Properties["displayName"] != null && obj_de.Properties["displayName"].Value != null)
{
de.Properties["displayName"].Value = "Smith, Rio (Welcome)";
de.CommitChanges();
}
}
로그인 후 복사

The above code describes the CommitChanges(), which will save the changes made in the Active Directory. The most important thing is that whatever changes are made will not be immediately visible in the applications of Active Directory like users of Active Directory and computers in the control panel it takes around 5-30 minutes to visible during changes because it needs to synchronize over the servers all through the network.

Querying Multiple Users in Active Directory with C# ASP .NET

The code above explained was to query the single DirectoryEntry object, whereas if we required for the list of objects we need to use the type SearchResultCollection joined with obj_deSearch, to search out all the things instead of finding one,

SearchResultCollection findUsers = retrieve_allUsers();
if (findUsers!= null && findUsers.Count > 0)
{
foreach (SearchResult getUser in findUsers)
{
DirectoryEntry obj_de = getUser.GetDirectoryEntry();
}
}
로그인 후 복사

Conclusion

In this article, I have explained about the Active Directory and how to retrieve details of users, system usage, groups, and also to authenticate the user. By using some classes, we can easily retrieve the details from the active directory (AD) database. Active Directory with C# is a foremost tool for enterprise networks and for businesses. When designing with web applications which suit for desktop applications to the web to make powerful organizations.

위 내용은 C#을 사용한 Active Directory의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!