아래의 코드를 사용하여 로그인 한 사용자에 대한 다양한 정보를 얻고 작동하지만 원하는 속성을 전달할 수있는 방법으로 바꾸고 싶습니다. DisplayName
, EmailAddress
등) 그리고 누구든지 로그인 한 상태에서이 값을 반환합니다. 어떻게 작동 시킬지 알 수 없었습니다.LDAP/AD에서 사용자 세부 정보를 얻는 방법
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
using (UserPrincipal user = UserPrincipal.FindByIdentity(context, User.Identity.Name))
{
if (user != null)
{
loggedInUserfullName = user.DisplayName;
loggedInUserEmail = user.EmailAddress;
}
}
}
위의 코드는 작동하지만 메소드의 범위를 벗어나는 변수는 사용할 수 없으므로 유용하지 않습니다. 난 그냥 DisplayName
를 얻기 위해 아래의 방법을 시도했지만 FindByIdentity
문자열 기대로 인해 오류가있어
(I 사용자의 이름을 가진 문자열이없는은 - 그게 내가 찾아 노력하고있어입니다!)
public string getUserFullName(object user)
{
user = UserPrincipal.FindByIdentity(ContextType.Domain, user);
string loggedInUserDisplayName = user.DisplayName;
return loggedInUserDisplayName ;
}
UserPrincipal loggedInUser = new UserPrincipal(ContextType.Domain);
// line above throws cannot convert from 'System.DirectoryServices.AccountManagement.ContextType' to 'System.DirectoryServices.AccountManagement.PrincipalContext'
getUserDetails(loggedInUser);
이 방법이 있습니까? 내가 원하는 것을 얻기 위해 잘못된 라이브러리를 사용하고 있습니까?
Windows 인증을 사용하는 웹 응용 프로그램입니다.
감사
System.DirectoryServices.AccountManagement를 사용하여 :
여기는 사용자 정보 클래스 :
편집
여러 필드를 포함하는 객체를 반환하려면, 당신은 같은 뭔가를 할 수 ; 당신은 이것을 가지고 있습니까 – MethodMan
예, 그것이 프로젝트에 포함되어 있습니다. –