次の方法で共有


SessionAuthenticationModule.SessionSecurityTokenCreated イベント

定義

セッション セキュリティ トークンが作成されたときに発生します。

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) 

イベントの種類

次のコードは、ASP.NET Web アプリケーションのglobal.asax.cs ファイルに実装された SessionSecurityTokenCreated イベントのハンドラーを示しています。 イベントにハンドラーを追加する必要もあります。 SessionAuthenticationModuleの概要に関するトピックでは、より完全な例を示します。

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

注釈

このイベントを使用して、セッション セキュリティ トークンを Cookie に書き込む前に変更できます。

SessionSecurityTokenCreated イベントは、セッション トークン (SessionSecurityToken) が作成された後、OnAuthenticateRequest メソッド内から発生します。 これは、たとえば、 SessionSecurityTokenReceived イベントのイベント ハンドラーによってトークンが変更された場合に発生します。

このイベントを使用して、パイプラインに沿ってさらに渡される前にセッション トークンのプロパティを変更し、要求を行うエンティティ (ユーザー) を認証するために使用できます。

イベント ハンドラーでは、 SessionSecurityTokenCreatedEventArgs.SessionToken プロパティを使用してトークンにアクセスできます。 トークンを変更した後、 SessionSecurityTokenCreatedEventArgs.WriteSessionCookie プロパティを true に設定することで、トークンが Cookie に確実に書き戻されるようにすることができます。 SessionSecurityTokenCreated イベントとは異なり、SessionSecurityTokenCreatedは取り消し可能なイベントではありません。

適用対象