How-to read "session index"

i’m developing a SAML authentication for our apps, all went fine with encryption, signature verification, …
Actually i’m stuck trying to read the “session index” that i see in the trace:

Name ID: <saml:NameID Format=“urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified” xmlns:saml=“urn:oasis:names:tc:SAML:2.0:assertion”>johndoe</saml:NameID>
Session index: 04386a0f-753e-47ea-83e8-ad39eab656d4::51231c12-467e-49f2-b427-c01d296d2ae5

i believe this index can be usefull to my needs, i wish to save it in a custom table with some other information from the assertion to make them available to other applications

thks in advance

The following code demonstrates retrieving the session index from the authn statement.


// Save the session index from the SAML assertion.
string sessionIndex;

_samlServiceProvider.Events.OnSamlAssertionReceived += (httpContext, samlAssertion) =>
{
var authenticationStatements = samlAssertion.GetAuthenticationStatements();

if (authenticationStatements != null && authenticationStatements.Count > 0)
{
sessionIndex = authenticationStatements[0].SessionIndex;
}
};

// Receive and process the SAML assertion contained in the SAML response.
// The SAML response is received either as part of IdP-initiated or SP-initiated SSO.
var ssoResult = await _samlServiceProvider.ReceiveSsoAsync();