Freigeben über


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 aktuellen HttpContext Objekts 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

Die FormsAuthenticationModule aktuelle HttpContext.User Eigenschaft wird auf ein IPrincipal Objekt festgelegt, das die Benutzeridentität für die aktuelle Anforderung darstellt, wenn die Authentifizierung Mode im Authentifizierungselementelement (ASP.NET Settings Schema) der Konfigurationsdatei der Anwendung festgelegt Forms ist.

Das FormsAuthenticationModule Verfügbarmachen eines Authenticate Ereignisses, mit dem Sie ein benutzerdefiniertes IPrincipal Objekt für die User Eigenschaft des aktuellen HttpContextObjekts bereitstellen können. Auf das Authenticate Ereignis wird zugegriffen, indem sie eine Unterroutine namens FormsAuthentication_OnAuthenticate in der Datei "Global.asax" für Ihre ASP.NET-Anwendung angeben.

Hinweis

In IIS 7.0 wird die Verwendung mit der WindowsAuthenticationModuleFormsAuthenticationModule Zeichenfolge nicht unterstützt. Weitere Informationen zu Kompatibilitätsproblemen in integrierten Modi finden Sie unter Verschieben einer ASP.NET Anwendung von IIS 6.0 auf IIS 7.0.

Konstruktoren

Name Beschreibung
FormsAuthenticationModule()

Initialisiert eine neue Instanz der FormsAuthenticationModule-Klasse.

Methoden

Name Beschreibung
Dispose()

Gibt alle Ressourcen außer Arbeitsspeicher frei, die von der FormsAuthenticationModule.

Equals(Object)

Bestimmt, ob das angegebene Objekt dem aktuellen Objekt entspricht.

(Geerbt von Object)
GetHashCode()

Dient als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
Init(HttpApplication)

Initialisiert das FormsAuthenticationModule-Objekt.

MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
ToString()

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

(Geerbt von Object)

Ereignisse

Name Beschreibung
Authenticate

Tritt auf, wenn die Anwendung die aktuelle Anforderung authentifiziert.

Gilt für:

Weitere Informationen