답변

0

Application_Start()은 ASP.NET 응용 프로그램의 첫 번째 리소스 (예 : 페이지)가 요청 될 때 호출됩니다. 또한 응용 프로그램의 수명주기 동안 한 번만 호출됩니다. 즉, 그 시점에 모든 사용자를 인증 할 수는 없을 것입니다. 클라이언트 컴퓨터의 현재 Windows 사용자 정보는 웹 서버 [Wiki]과의 해싱을 포함하는 암호화 교환을 통해 웹 브라우저에서 제공됩니다. 그런 다음에는 사용자를 인증 할 수 있습니다. 따라서 User.Identity.IsAuthenticated은 페이지로드시 작동해야합니다 (아래 코드 참조). 당신은 당신이 일반적인 방법에 필요한 논리를 추출하고 페이지가로드

처음에 호출 할 수 있습니다
protected void Page_Load(object sender, EventArgs e) 
{ 
    if (User.Identity.IsAuthenticated) 
    { 
     Page.Title = "Home page for " + User.Identity.Name; 
     // add your logic here 
    } 
    else 
    { 
     // you get here if auth failed. 
     Page.Title = "Home page for guest user."; 
    } 
} 

더 많은 정보를 원하시면 귀하의 갱신 후 :

내가 확인하기 위해 Application_Start()를 사용 것이며, 역할이 아직 없으면 추가하십시오.

if (! Roles.RoleExists("Auditors")) 
      Roles.CreateRole("Auditors"); 

당신은 도움이 게시물을 찾을 수 있습니다 :

protected void Application_AuthenticateRequest(Object sender, EventArgs e) 
{ 
    if (HttpContext.Current.User != null) 
    { 
     if (HttpContext.Current.User.Identity.IsAuthenticated) 
     { 
      if (HttpContext.Current.User.Identity is WindowsIdentity) 
      { 
       if (string.IsNullOrEmpty(Usuario.Nome)) 
       { 

당신이 클릭 (Alt + 프로젝트에 입력) 속성을 프로젝트로, 반드시합니다 http://weblogs.asp.net/scottgu/Recipe_3A00_-Implementing-Role_2D00_Based-Security-with-ASP.NET-2.0-using-Windows-Authentication-and-SQL-Server

+0

안녕 없다, 나는이 같은 노력했다 : 보호 무효를 Application_AuthenticateRequest (개체 보낸 사람, EventArgs입니다 전자) { 을 경우 (HttpContext.Current.User = 널!) { 경우 (HttpContext.Current. (HttpContext.Current.User.Identity가 WindowsIdentity 인 경우) { var amduser = new UsuarioDB(); amduser.DefinirPropriedadesUsuario(); } } } } 그러나 Current.User.Identity는 항상 null입니다. –

+0

@ user1200656이 시도해 볼 수 있습니까? http://stackoverflow.com/questions/1663535/httpcontext-current-user-is-null-even-though-windows-authentication-is-on –

1

을 나는이 사용 WEB에 NTLM 인증 확인.

이것은 나를 위해 일했습니다. 지금 HttpContext.Current.User.Identity가 더 이상 널

+0

Microsoft는 더 이상 응용 프로그램에서 NTLM을 권장하지 않습니다. –

+0

이것이 유일한 방법입니다. 다른 모든 방법 User.Identity.IsAuthenticated는 Visual Studio에서 응용 프로그램을 실행할 때 null이되었습니다 –

+0

이것을 시도해 볼 수 있습니까? http://stackoverflow.com/questions/1663535/httpcontext-current-user-is-null-even-though-windows-authentication-is-on –