2014-03-04 1 views
1

나는 둘러 보았지만 여전히 이에 대한 대답을 얻지 못했습니다.ASP.Net 전역 파일 내에서 사용자 ID를 얻는 중

나는 ASP.NET 응용 프로그램이 있으며 Windows 인증을 사용합니다. 의 Web.config가 제대로 구성 : WindowsAuthentication_Authenticate (개체를 보낸 사람, WindowsAuthenticationEventArgs 전자) 사용자 ID지고

코드 :

var userId = String.Empty; 
     //Dispalys the UserName from AD. 
     System.Security.Principal.IPrincipal User; 
     User = System.Web.HttpContext.Current.User; 
     if (User != null) 
     { 
      string username = User.Identity.Name; 
      username = username.Substring(username.IndexOf("\\") + 1); 

      CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; 
      TextInfo textInfo = cultureInfo.TextInfo; 
      userId = (textInfo.ToTitleCase(username)); 
     } 

<authentication mode="Windows"/> 
    <authorization> 
     <deny users="?"/> 
    </authorization> 

나는 방법에서 사용자 ID를 얻고있다 System.Web.HttpContext.Current.User는이 경우 항상 null입니다.

여기서 내가 뭘 잘못하고 있니?

답변

2

WindowsAuthentication_Authenticate 방법의 인수 중 하나는 WindowsAuthenticationEventArgs 유형입니다. 속성 중 하나는 Identity이므로 e.Identity.Name을 작성하여 사용자 이름에 액세스 할 수 있어야합니다.

참조 링크 :

관련 문제