FormsAuthenticationModule.Authenticate Gebeurtenis
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Vindt plaats wanneer de toepassing de huidige aanvraag verifieert.
public:
event System::Web::Security::FormsAuthenticationEventHandler ^ Authenticate;
public event System.Web.Security.FormsAuthenticationEventHandler Authenticate;
member this.Authenticate : System.Web.Security.FormsAuthenticationEventHandler
Public Custom Event Authenticate As FormsAuthenticationEventHandler
Gebeurtenistype
Voorbeelden
In het volgende codevoorbeeld wordt de gebeurtenis FormsAuthentication_OnAuthenticate gebruikt om de User eigenschap van de huidige HttpContext in te stellen op een GenericPrincipal object met een aangepast object 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
Opmerkingen
De Authenticate gebeurtenis wordt gegenereerd tijdens de AuthenticateRequest gebeurtenis.
U kunt de gebeurtenis Authenticate van de klasse FormsAuthenticationModule afhandelen door een subroutine met de naam FormsAuthentication_OnAuthenticate op te geven in het bestand Global.asax voor uw ASP.NET toepassing.
U kunt de FormsAuthenticationEventArgsUser eigenschap die is opgegeven aan de FormsAuthentication_OnAuthenticate gebeurtenis gebruiken om de User eigenschap van de huidige HttpContext in te stellen op een aangepast IPrincipal object. Als u tijdens de FormsAuthentication_OnAuthenticate gebeurtenis geen waarde voor de User eigenschap opgeeft, wordt de identiteit van het formulierverificatieticket in de cookie of URL gebruikt.
De gebeurtenis FormsAuthentication_OnAuthenticate wordt alleen gegenereerd wanneer de verificatiemodus is ingesteld op Forms in het element authentication Element (ASP.NET Settings Schema) element van het configuratiebestand van de toepassing en de FormsAuthenticationModule is een actieve HTTP-module voor de toepassing.