2014-04-09 3 views
0

여기 연구하기 어려운 질문이 있습니다. 가장을 사용할 때 로그인 한 "실제"사용자의 이름을 얻는 방법은 무엇입니까? 내가 가장을 껐다가 다시 켰다면 가능할 수도 있다는 것을 알고 있습니다.하지만 상황이 어렵고 더 단순한 것을 찾고 있습니다.가장을 사용할 때 실제 로그인 한 사용자 가져 오기

 if (LogonUser(userName, "ABDATA", pwd, LogonSessionType.Interactive, LogonProvider.Default, ref this._userToken)) 
     { 
      if (DuplicateToken(this._userToken, SecurityImpersonationLevel.SecurityImpersonation, ref this._impersonationToken)) 
      { 
       this._identity = new WindowsIdentity(this._impersonationToken, "Kerberos", WindowsAccountType.Normal, true); 
       this._impersonationContext = this._identity.Impersonate(); 
       System.Threading.Thread.CurrentPrincipal = new WindowsPrincipal(this._identity); 
      } 
      else 
      { 
       Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); 
      } 
     } 
: 여기 Environment.UserName WindowsIdentity.GetCurrent().Name SystemInformation.Username

사용자 (이 도움이 얼마나 확실하지)를 가장합니다 코드입니다 :

나는 ImpersonationUser 모든 포인트가있는 다음을 시도했습니다

기본적으로이 가장 사용자의 권한을 사용하여 특정 파일에 액세스 할 수 있지만 책임감을 위해 실제 로그인 한 사용자의 이름을 표시 할 수 있기를 원합니다.

정말 해결책을 찾고 .. 감사합니다.

+1

가장 블록 앞에 실제 사용자 이름을 가져 와서 변수에 할당 된 상태로 유지할 수 있습니까? – Kurubaran

+0

그것이 내가 생각한 첫 번째 문제이며, 어려운 부분입니다. 불행하게도, 매개 변수를 전달할 수있는 메소드와 필요로하는 메소드 사이에는 벽이 있습니다. 뭔가 Type.InvokeMember를 호출했습니다. 기본적으로 이것은 "트랜잭션"(SQL 트랜잭션이 아닌)을 실행하고 트랜잭션에 단계가있는 메소드입니다. 나는이 단계 중 하나에 변수를 가져 가야 할 것입니다.하지만 그렇게 할 수없는 것 같습니다. 정의로 갈 때 메타 데이터로 이동합니다. – Paul

+0

ASP.NET 응용 프로그램 또는 데스크톱 응용 프로그램? –

답변