FormsAuthenticationModule Klasse

Definition

Legt die Identität des Benutzers für eine ASP.NET-Anwendung fest, wenn die Formularauthentifizierung aktiviert ist. Diese Klasse kann nicht vererbt werden.

public ref class FormsAuthenticationModule sealed : System::Web::IHttpModule
public sealed class FormsAuthenticationModule : System.Web.IHttpModule
type FormsAuthenticationModule = class
    interface IHttpModule
Public NotInheritable Class FormsAuthenticationModule
Implements IHttpModule
Vererbung
FormsAuthenticationModule
Implementiert

Beispiele

Im folgenden Beispiel wird das FormsAuthentication_OnAuthenticate-Ereignis verwendet, um die User Eigenschaft des current HttpContext auf ein benutzerdefiniertes IPrincipal Objekt festzulegen.

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

Hinweise

Legt FormsAuthenticationModule die aktuelle HttpContext.User Eigenschaft auf ein IPrincipal Objekt fest, das die Benutzeridentität für die aktuelle Anforderung darstellt, wenn die Authentifizierung Mode im Authentifizierungselement (ASP.NET Einstellungsschema) der Konfigurationsdatei der Anwendung auf Forms festgelegt ist.

Macht FormsAuthenticationModule ein Authenticate -Ereignis verfügbar, mit dem Sie ein benutzerdefiniertes IPrincipal Objekt für die User -Eigenschaft des aktuellen HttpContextbereitstellen können. Auf Authenticate das Ereignis wird zugegriffen, indem Sie eine Unterroutine mit dem Namen FormsAuthentication_OnAuthenticate in der Datei Global.asax für Ihre ASP.NET-Anwendung angeben.

Hinweis

In IIS 7.0 wird die Verwendung von WindowsAuthenticationModule mit dem FormsAuthenticationModule nicht unterstützt. Weitere Informationen zu Kompatibilitätsproblemen in integrierten Modi finden Sie unter Verschieben einer ASP.NET-Anwendung von IIS 6.0 zu IIS 7.0.

Konstruktoren

FormsAuthenticationModule()

Initialisiert eine neue Instanz der FormsAuthenticationModule-Klasse.

Methoden

Dispose()

Gibt alle Ressourcen mit Ausnahme des Arbeitsspeichers frei, die vom FormsAuthenticationModule verwendet werden.

Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
GetHashCode()

Fungiert als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft den Type der aktuellen Instanz ab.

(Geerbt von Object)
Init(HttpApplication)

Initialisiert das FormsAuthenticationModule-Objekt.

MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Ereignisse

Authenticate

Tritt ein, wenn die Anwendung die aktuelle Anforderung authentifiziert.

Gilt für:

Weitere Informationen