SessionAuthenticationModule.SessionSecurityTokenCreated Evento

Definizione

Si verifica quando viene creato un token di sicurezza della sessione.

public:
 event EventHandler<System::IdentityModel::Services::SessionSecurityTokenCreatedEventArgs ^> ^ SessionSecurityTokenCreated;
public event EventHandler<System.IdentityModel.Services.SessionSecurityTokenCreatedEventArgs> SessionSecurityTokenCreated;
member this.SessionSecurityTokenCreated : EventHandler<System.IdentityModel.Services.SessionSecurityTokenCreatedEventArgs> 
Public Custom Event SessionSecurityTokenCreated As EventHandler(Of SessionSecurityTokenCreatedEventArgs) 
Public Event SessionSecurityTokenCreated As EventHandler(Of SessionSecurityTokenCreatedEventArgs) 

Tipo evento

Esempio

Il codice seguente mostra un gestore per l'evento SessionSecurityTokenCreated implementato nel file global.asax.cs di un'applicazione Web di ASP.NET. È anche necessario aggiungere il gestore all'evento. Nell'argomento SessionAuthenticationModule di panoramica viene visualizzato un esempio più completo.

void SessionAuthenticationModule_SessionSecurityTokenCreated(object sender, SessionSecurityTokenCreatedEventArgs e)
{
    System.Diagnostics.Trace.WriteLine("Handling SessionSecurityTokenCreated event");
    //Store session on the server-side token cache instead writing the whole token to the cookie.
    //It may improve throughput but introduces server affinity that may affect scalability
    FederatedAuthentication.SessionAuthenticationModule.IsReferenceMode = true;
}

Commenti

È possibile usare questo evento per modificare il token di sicurezza della sessione prima di essere scritto in un cookie.

L'evento SessionSecurityTokenCreated viene generato dall'interno del OnAuthenticateRequest metodo dopo la creazione di un token di sessione (SessionSecurityToken). Ciò accade, ad esempio, se un gestore eventi per l'evento SessionSecurityTokenReceived modifica il token.

È possibile usare questo evento per modificare le proprietà del token di sessione prima di passare ulteriormente lungo la pipeline e viene usato per autenticare l'entità che effettua la richiesta (utente).

In un gestore eventi è possibile accedere al token tramite la SessionSecurityTokenCreatedEventArgs.SessionToken proprietà . Dopo aver modificato il token, è possibile assicurarsi che venga scritto nuovamente nel cookie impostando la SessionSecurityTokenCreatedEventArgs.WriteSessionCookie proprietà su true. A differenza dell'evento SessionSecurityTokenCreated , SessionSecurityTokenCreated non è un evento annullabile.

Si applica a