Dela via


DistributedSession Class

Definition

An ISession backed by an IDistributedCache.

public ref class DistributedSession : Microsoft::AspNetCore::Http::ISession
public class DistributedSession : Microsoft.AspNetCore.Http.ISession
type DistributedSession = class
    interface ISession
Public Class DistributedSession
Implements ISession
Inheritance
DistributedSession
Implements

Constructors

DistributedSession(IDistributedCache, String, TimeSpan, Func<Boolean>, ILoggerFactory, Boolean)
DistributedSession(IDistributedCache, String, TimeSpan, TimeSpan, Func<Boolean>, ILoggerFactory, Boolean)

Initializes a new instance of DistributedSession.

Properties

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.

IsAvailable

Indicates whether the current session loaded successfully. Accessing this property before the session is loaded will cause it to be loaded inline.

Keys

Enumerates all the keys, if any.

Methods

Clear()

Remove all entries from the current session, if any. The session cookie is not removed.

CommitAsync()
CommitAsync(CancellationToken)

Store the session in the data store. This may throw if the data store is unavailable.

LoadAsync()
LoadAsync(CancellationToken)

Load the session from the data store. This may throw if the data store is unavailable.

Remove(String)

Remove the given key from the session if present.

Set(String, Byte[])

Set the given key and value in the current session. This will throw if the session was not established prior to sending the response.

TryGetValue(String, Byte[])

Retrieve the value of the given key, if present.

Extension Methods

Get(ISession, String)

Gets a byte-array value from ISession.

GetInt32(ISession, String)

Gets an int value from ISession.

GetString(ISession, String)

Gets a string value from ISession.

SetInt32(ISession, String, Int32)

Sets an int value in the ISession.

SetString(ISession, String, String)

Sets a String value in the ISession.

Applies to