0
해당 도메인을 쿼리하기 위해 다른 도메인에서 사용자를 가장하려고 시도하고 있습니다. 배경에 대해서는 Accessing user info from a one way trust을 참조하십시오.다른 도메인의 사용자로 가장 (단방향 트러스트)
로컬 도메인 사용자를 사용할 때 가장 (impersonation)이 올바르게 작동합니다. LDAPS 포트 636을 초과하는 대상 도메인을 지정하면 작동하지 않습니다. 나의 가장은 null을 반환합니다.
내 가장을 코드
public static WindowsImpersonationContext ImpersonateUser(ConnectionCredentials user)
{
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if (RevertToSelf())
{
if (LogonUser(user.UserName, user.Domain, user.Password, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, ref token) != 0)
{
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null)
{
CloseHandle(token);
CloseHandle(tokenDuplicate);
return impersonationContext;
}
}
}
}
if (token != IntPtr.Zero)
CloseHandle(token);
if (tokenDuplicate != IntPtr.Zero)
CloseHandle(tokenDuplicate);
return impersonationContext;
}
어떤 아이디어가? 감사합니다. .
impersonationContext가 null이라는 것을 의미합니까? impersonationContext가 올바른 범위에서 선언되지 않았으므로 코드가 어떻게 작동하는지 알지 못합니다. GetLastError를 사용하여 LogonUser에서 반환 된 오류 코드를 확인하십시오. –