Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

interface Microsoft.​AspNetCore.​Http.​ISession

Assembly: Microsoft.AspNetCore.Http.Features

Stores user data while the user browses a web application. Session state uses a store maintained by the application to persist data across requests from a client. The session data is backed by a cache and considered ephemeral data.

Properties

bool
IsAvailable
Indicates whether the current session loaded successfully. Accessing this property before the session is loaded will cause it to be loaded inline.
string
Id
A unique identifier for the current session. This is not the same as the session cookie since the cookie lifetime may not be the same as the session entry lifetime in the data store.
Enumerates all the keys, if any.

Methods

LoadAsync​(System.​Threading.​CancellationToken cancellationToken = null)
Load the session from the data store. This may throw if the data store is unavailable.
CommitAsync​(System.​Threading.​CancellationToken cancellationToken = null)
Store the session in the data store. This may throw if the data store is unavailable.
bool
TryGetValue​(string key, System.​Byte[]&? value)
void
Set​(string key, byte[] value)
Set the given key and value in the current session. This will throw if the session was not established prior to sending the response.
void
Remove​(string key)
Remove the given key from the session if present.
void
Clear​()
Remove all entries from the current session, if any. The session cookie is not removed.