FormsAuthenticationEventArgs Classe

Definizione

Specifica i dati per l'evento FormsAuthentication_OnAuthenticate. La classe non può essere ereditata.

public ref class FormsAuthenticationEventArgs sealed : EventArgs
public sealed class FormsAuthenticationEventArgs : EventArgs
type FormsAuthenticationEventArgs = class
    inherit EventArgs
Public NotInheritable Class FormsAuthenticationEventArgs
Inherits EventArgs
Ereditarietà
FormsAuthenticationEventArgs

Esempio

Nell'esempio di codice seguente viene usato l'evento FormsAuthentication_OnAuthenticate per impostare la User proprietà dell'oggetto corrente HttpContext su un GenericPrincipal oggetto con un oggetto personalizzato Identity.

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

Commenti

La FormsAuthenticationEventArgs classe viene usata per fornire valori di evento all'evento FormsAuthentication_OnAuthenticate e consentire di specificare un'identità personalizzata per la richiesta corrente.

Costruisce FormsAuthenticationModule un FormsAuthenticationEventArgs oggetto usando l'oggetto corrente HttpContext e lo passa all'evento FormsAuthentication_OnAuthenticate .

È possibile usare la User proprietà per impostare la User proprietà dell'oggetto corrente HttpContext su un oggetto personalizzato IPrincipal .

Se non si specifica un valore per la proprietà durante l'evento UserFormsAuthentication_OnAuthenticate , viene usata l'identità fornita dal ticket di autenticazione dei moduli nel cookie o nell'URL.

L'evento FormsAuthentication_OnAuthenticate viene generato solo quando l'autenticazione Mode è impostata su Forms e l'oggetto FormsAuthenticationModule è un modulo HTTP attivo per l'applicazione.

Costruttori

FormsAuthenticationEventArgs(HttpContext)

Inizializza una nuova istanza della classe FormsAuthenticationEventArgs.

Proprietà

Context

Ottiene l'oggetto HttpContext relativo alla richiesta HTTP corrente.

User

Ottiene o imposta l'oggetto IPrincipal da associare alla richiesta corrente.

Metodi

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Vedi anche