2014-12-12 3 views
2

사용자가 Active Directory에 있는지 확인하고 사용자 계정이 사용되는지 확인하는 웹 서비스를 작성하고 있습니다. 일단 확인하면, 나는 그들의 사용자 계정을 검증한다. 성공적으로 사용자 이름과 비밀번호를 입력하면 인증하는 사람의 GUID 또는 NativeGuid 번을 받고 싶습니다. GUID 또는 NativeGUID을 사용하여 SQL Server 데이터베이스 내에서 관계를 구축하고 싶습니다. 내가 다른 사용자의 GUID 또는 NativeGUID 그것은 나에게 같은 ID을 반환하는 것 하나 하나 시간을 얻을 때Active Directory에서 GUID 또는 기본 GUID 가져 오기

public string isAuthenticated (string serverName, string userName, string pwd) 
{ 
    string _serverName, _userName, _pwd; 
    _serverName = serverName; 
    _userName = userName; 
    _pwd = pwd; 

    string message; 

    if (DoesUserExist (_userName) == true) 
    { 
     if (isActive(userName) == true) 
     { 
      try 
      { 
       DirectoryEntry entry = new DirectoryEntry(_serverName, _userName, _pwd); 
       object nativeObject = entry.NativeObject; 
       //issue is here 
       string GUID = entry.Guid.ToString(); 
       string GUIDID = entry.NativeGuid; 
       //end of issue 
       message = "Successfully authenticated"; 
      } 
      catch(DirectoryServicesCOMException ex) 
      { 
        message = ex.Message; 
      } 
     } 
     else 
     { 
       message = "Account is disabled"; 
     } 
    } 
    else 
    { 
     message = "There's an issue with your account."; 
    } 
    return message;  
} 

:

는 여기에 내가 데려 갈거야 접근이다.

Active Directory의 다른 개체에 대해 UNIQUE ID을 얻으려면 다른 방법이 있습니까?

감사

답변

3

당신이 .NET 3.5 및 최대에 있다면, 당신은 System.DirectoryServices.AccountManagement (S.DS.AM) 네임 스페이스를 확인해야합니다. 여기에 대한 모든 읽기 :

// set up domain context 
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain)) 
{ 
    // find a user 
    UserPrincipal user = UserPrincipal.FindByIdentity(ctx, _userName); 

    if(user != null) 
    { 
     // get the GUID 
     var objectGuid = user.Guid; 
    } 
} 

을 : MSDN docs on System.DirectoryServices.AccountManagement

기본적으로

  • Managing Directory Security Principals in the .NET Framework 3.5
  • , 당신은 AD에서 사용자 및/또는 그룹을 쉽게 찾을 도메인 컨텍스트를 정의 할 수 있습니다 새로운 S.DS.AM을 사용하면 광고에서 사용자 및 그룹과 함께 놀 수 있습니다. 지금 테스트 할 AD가 없습니다.하지만 실제로 이것이 사용자 객체의 objectGuid 속성 값을 제공하기를 바랍니다.

+0

예이 기능이 작동합니다. 거의 동일한 코드를 붙여 넣으려고했습니다. UPV – MajkeloDev

+0

@marc_s 감사합니다. 이것은 내가 필요한 것입니다. – smr5