Export (0) Print
Expand All

SessionAuthenticationModule.SessionSecurityTokenCreated Event

.NET Framework 4.5

Occurs when a session security token has been created.

Namespace:  System.IdentityModel.Services
Assembly:  System.IdentityModel.Services (in System.IdentityModel.Services.dll)

public event EventHandler<SessionSecurityTokenCreatedEventArgs> SessionSecurityTokenCreated

You can use this event to modify the session security token before it is written to a cookie.

The SessionSecurityTokenCreated event is raised from within the OnAuthenticateRequest method after a session token (SessionSecurityToken) has been created. This happens, for example, if an event handler for the SessionSecurityTokenReceived event modifies the token.

You can use this event to modify properties of the session token before it is passed further along the pipeline and is used to authenticate the entity making the request (user).

In an event handler, you can access the token through the SessionSecurityTokenCreatedEventArgs.SessionToken property. After modifying the token, you can ensure that it is written back to the cookie by setting the SessionSecurityTokenCreatedEventArgs.WriteSessionCookie property to true. Unlike, the SessionSecurityTokenCreated event, SessionSecurityTokenCreated is not a cancelable event.

The following code shows a handler for the SessionSecurityTokenCreated event implemented in the global.asax.cs file of an ASP.NET web application. You must also add the handler to the event. A more complete example is shown in the SessionAuthenticationModule overview topic.

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;
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft