WSFederationAuthenticationModule.SessionSecurityTokenCreated 事件

定義

根據從安全性權杖服務 (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 之前,先新增事件處理常式來修改會話權杖。 在事件處理常式中,您可以透過 SessionSecurityTokenCreatedEventArgs.SessionToken 屬性存取會話權杖。 您可以藉由設定 SessionSecurityTokenCreatedEventArgs.WriteSessionCookie 屬性來指定是否應該寫入會話 Cookie。

處理從安全性權杖服務收到的WS-Federation登入回應訊息 (「wsignin1.0」) 從安全性權杖服務接收 (STS) 時,這個事件會從事件處理常式委派內 OnAuthenticateRequest 引發。 它只會在已驗證登入回應訊息中從 wresult 或 wresultptr 參數還原序列化的安全性權杖之後,以及在宣告主體設定 Thread.CurrentPrincipal 于 (和 User) 的 HttpContext.Current 屬性之前引發。

重要

若要在參考模式中操作會話,Microsoft 建議在 WSFederationAuthenticationModule.SessionSecurityTokenCreated global.asax.cs 檔案中提供事件的處理常式,並在傳入屬性的 SessionSecurityTokenCreatedEventArgs.SessionToken 權杖上設定 SessionSecurityToken.IsReferenceMode 屬性。 這可確保會話權杖會以每個要求的參考模式運作,而且偏好只設定 SessionAuthenticationModule.IsReferenceMode 會話驗證模組上的 屬性。

適用於