WSFederationAuthenticationModule.SessionSecurityTokenCreated 事件
定义
当会话安全标记已从安全标记服务标记 (STS) 创建时发生。Occurs when a session security token has been created from the security token received from a security token service (STS).
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)
事件类型
示例
void WSFederationAuthenticationModule_SessionSecurityTokenCreated(object sender, SessionSecurityTokenCreatedEventArgs e)
{
//Manipulate session token here, for example, changing its expiration value
System.Diagnostics.Trace.WriteLine("Handling SessionSecurityTokenCreated event");
System.Diagnostics.Trace.WriteLine("Key valid from: " + e.SessionToken.KeyEffectiveTime);
System.Diagnostics.Trace.WriteLine("Key expires on: " + e.SessionToken.KeyExpirationTime);
}
注解
你可以添加一个事件处理程序来修改会话令牌,然后将其用于设置线程主体并将其写入会话 cookie。You can add an event handler to modify the session token before it is used to set the thread principal and is written to the session cookie. 在事件处理程序中,可以通过属性访问会话令牌 SessionSecurityTokenCreatedEventArgs.SessionToken 。In the event handler, you can access the session token through the SessionSecurityTokenCreatedEventArgs.SessionToken property. 可以通过设置属性来指定是否应写入会话 cookie SessionSecurityTokenCreatedEventArgs.WriteSessionCookie 。You can specify whether a session cookie should be written by setting the SessionSecurityTokenCreatedEventArgs.WriteSessionCookie property.
OnAuthenticateRequest当处理 WS-Federation 登录响应消息时,将从事件处理程序委托内部引发此事件, ( "wsignin1.0 1.0" ) 从 security token service (STS) 接收。This event is raised from inside the OnAuthenticateRequest event-handler delegate when processing a WS-Federation sign-in response message ("wsignin1.0") received from the security token service (STS). 仅在验证了从 wresult 反序列化的安全令牌或登录响应消息中的 wresultptr 参数之后、在 Thread.CurrentPrincipal (上和) 的属性上设置声明主体后引发 User HttpContext.Current 。It is raised just after the security token that was deserialized from the wresult or the wresultptr parameter in the sign-in response message has been validated, and before the claims principal is set on the Thread.CurrentPrincipal (and on the User property of HttpContext.Current).
重要
若要在引用模式下操作会话,Microsoft 建议为 WSFederationAuthenticationModule.SessionSecurityTokenCreated global.asax .cs 文件中的事件提供处理程序,并在 SessionSecurityToken.IsReferenceMode 属性中传递的标记上设置属性 SessionSecurityTokenCreatedEventArgs.SessionToken 。To operate sessions in reference mode, Microsoft recommends providing a handler for the WSFederationAuthenticationModule.SessionSecurityTokenCreated event in the global.asax.cs file and setting the SessionSecurityToken.IsReferenceMode property on the token passed in the SessionSecurityTokenCreatedEventArgs.SessionToken property. 这将确保会话令牌在对每个请求的引用模式下运行,并且优于仅在 SessionAuthenticationModule.IsReferenceMode 会话身份验证模块上设置属性。This will ensure that the session token operates in reference mode for every request and is favored over merely setting the SessionAuthenticationModule.IsReferenceMode property on the Session Authentication Module.