다음을 통해 공유


FormsAuthenticationEventArgs.User 속성

정의

현재 요청과 연결할 개체를 가져오거나 설정합니다 IPrincipal .

public:
 property System::Security::Principal::IPrincipal ^ User { System::Security::Principal::IPrincipal ^ get(); void set(System::Security::Principal::IPrincipal ^ value); };
public System.Security.Principal.IPrincipal User { get; set; }
member this.User : System.Security.Principal.IPrincipal with get, set
Public Property User As IPrincipal

속성 값

IPrincipal 현재 요청과 연결할 개체입니다.

예제

다음 예제에서는 FormsAuthentication_OnAuthenticate 이벤트를 사용 하 여 사용자 지정 Identity개체에 GenericPrincipal 현재 HttpContext 속성을 설정 User 합니다.

public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
  if (FormsAuthentication.CookiesSupported)
  {
    if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
    {
      try
      {
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
          Request.Cookies[FormsAuthentication.FormsCookieName].Value);
        
        args.User = new System.Security.Principal.GenericPrincipal(
          new Samples.AspNet.Security.MyFormsIdentity(ticket),
          new string[0]);
      }
      catch (Exception e)
      {
        // Decrypt method failed.
      }
    }
  }
  else
  {
    throw new HttpException("Cookieless Forms Authentication is not " +
                            "supported for this application.");
  }
}
Public Sub FormsAuthentication_OnAuthenticate(sender As Object, _
                                              args As FormsAuthenticationEventArgs)
  If FormsAuthentication.CookiesSupported Then
    If Not Request.Cookies(FormsAuthentication.FormsCookieName) Is Nothing Then
      Try
        Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt( _
          Request.Cookies(FormsAuthentication.FormsCookieName).Value)
        
        args.User = New System.Security.Principal.GenericPrincipal( _
          New Samples.AspNet.Security.MyFormsIdentity(ticket), _
          New String(0) {})
      Catch e As HttpException
        ' Decrypt method failed.
      End Try
    End If
  Else
      Throw New Exception("Cookieless Forms Authentication is not " & _
                            "supported for this application.")
  End If
End Sub

설명

User 속성을 사용하여 현재 HttpContext 속성을 사용자 지정 IPrincipal 개체로 설정할 User 수 있습니다.

FormsAuthentication_OnAuthenticate 이벤트 중에 속성 값을 User 지정하지 않으면 쿠키 또는 URL의 양식 인증 티켓에서 제공하는 ID가 사용됩니다.

적용 대상

추가 정보