2012-06-04 3 views

답변

39

,

string Name = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name; 

또는

string Name = System.Environment.UserName 

또는

string Name = Environment.GetEnvironmentVariable("USERNAME"); 

또는

string Name = System.Security.Principal.WindowsIdentity.GetCurrent().Name; 

법과 KS :

+5

어쨌든 여기에 전혀 쓸모가없는 AD (현재 사용자가 누구인지 추적하지 못합니다 - 로그인 AD가 세션 중에 너무 많이 요청되지 않은 이후)는 아무 것도 없습니다. – TomTom

+5

웹 사이트가 있는데 Windows에 로그인 한 사용자의 사용자 이름을 얻으려는 중입니다. 위의 어느 것도 저에게 제공하지 않습니다./ – SearchForKnowledge

+2

정말 고마워요. 나는 항상 수색을하고 있었다. –

25
당신이 .NET 3.5 경우

최대, 당신은 사용할 수 있습니다

// set up domain context 
PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 

// find current user 
UserPrincipal user = UserPrincipal.Current; 

if(user != null) 
{ 
    string loginName = user.SamAccountName; // or whatever you mean by "login name" 
}  

새로운 S.DS.AM은 AD에서 사용자와 그룹에 놀러 정말 쉽게!

참고 :

+2

이 클라이언트 서버 환경에서 작동합니다. – Sunil

+3

@ user1306094 : Active Directory가있는 모든 환경에서 작동합니다. –

+0

안녕하세요, 도메인 내부에서 작업 중입니다. 다른 서버 또는 도메인 외부에서 작동시키는 방법 – Sunil

1
System.DirectoryServices.AccountManagement.UserPrincipal.Current.Name 

이 또한 나를 위해 노력하고 있습니다! 감사합니다

관련 문제