2009-04-24 5 views
5

나는 내 사용자 지정 로그인 시퀀스의 일부로서 Web.HttpContext.Current.User.Identity.Name의 출처는 어디입니까?

FormsAuthentication.SetAuthCookie("someName", True) 

있습니다. 지금까지 내가 말할 수있는

<location path="myPage.aspx"> 
    <system.web> 
     <authorization> 
      <allow roles="SomeRole"/> 
      <deny users="*"/> 
     </authorization> 
    </system.web> 
</location> 

, GetRolesForUser의 내 역할 공급자의 구현에 호출합니다 : 나중에, 난 단지 특정 역할을 수 있도록 일부 페이지가 있습니다. Web.HttpContext.Current.User.Identity.Name에서 username 매개 변수를 가져 오는 것 같습니다.

내 질문은 .... 인증 쿠키의 사용자 이름이 현재 사용자 신원의 이름으로 설정 되나요?

답변

3

이며, 그 객체가의 일환으로 귀하의 경우 아마도 System.Web.Security.FormsAuthenticationModule에, 표준 ASP.NET HttpModules는 중 하나로 설정 OnAuthenticate 메서드.

다른 사용자 이름이나 ID 설정과 같이이 정보를 변경하는 방법 만 알고 싶다면 Application_AuthenticateRequest를 재정의하는 global.asax 또는 사용자 지정 HTTPModule을 만드는 것이 좋습니다. 다음은 예입니다.

Public Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As System.EventArgs) 
    Dim cookieName As String = FormsAuthentication.FormsCookieName 
    Dim authCookie As HttpCookie = HttpContext.Current.Request.Cookies(FormsAuthentication.FormsCookieName) 

    If Not IsNothing(authCookie) Then 
     Dim authTicket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(authCookie.Value) 
     If IsNothing(authTicket) OrElse authTicket.Expired Then 
      HttpContext.Current.Response.Redirect(FormsAuthentication.LoginUrl) 
     Else 
      Dim id As New FormsIdentity(authTicket) 

      Dim newUser As New YourCustomUserType(id.Name) 
      HttpContext.Current.User = newUser 
     End If 
    End If 
End Sub 
2

System.Web.Security.FormsAuthenticationModule의 개인 메서드 OnAuthenticate 에서처럼 보입니다. 라인은 사용자 이름이 IPrinciple 사용자 개체의 단지 속성입니다

e.Context.SetPrincipalNoDemand(
     new GenericPrincipal(new FormsIdentity(ticket), 
     new string[0])); 
관련 문제