Interface ISession
Represents a session.
Namespace: EmbedIO.Sessions
Syntax
public interface ISession
Properties
Count
Gets the number of key/value pairs contained in a session.
Declaration
int Count { get; }
Property Value
Type | Description |
---|---|
Int32 | The number of key/value pairs contained in the object that implements ISession. |
Duration
Gets the time interval, starting from LastActivity, after which the session expires.
Declaration
TimeSpan Duration { get; }
Property Value
Type | Description |
---|---|
TimeSpan | The expiration time. |
Id
A unique identifier for the session.
Declaration
string Id { get; }
Property Value
Type | Description |
---|---|
String | The unique identifier for this session. |
See Also
IsEmpty
Gets a value that indicates whether a session is empty.
Declaration
bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
Boolean | true if the object that implements ISession is empty, i.e. contains no key / value pairs; otherwise, false. |
Item[String]
Gets or sets the value associated with the specified key.
Note that a session does not store null values; therefore, setting this property to null
has the same effect as removing key
from the dictionary.
Declaration
object this[string key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
String | key | The key of the value to get or set. |
Property Value
Type | Description |
---|---|
Object | The value associated with the specified key, if |
LastActivity
Gets the UTC date and time of last activity on the session.
Declaration
DateTime LastActivity { get; }
Property Value
Type | Description |
---|---|
DateTime | The UTC date and time of last activity on the session. |
Methods
Clear()
Removes all keys and values from a session.
Declaration
void Clear()
ContainsKey(String)
Determines whether a session contains an element with the specified key.
Declaration
bool ContainsKey(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key to locate in the object that implements ISession. |
Returns
Type | Description |
---|---|
Boolean | true if the object that implements ISession contains an element with the key; otherwise, false . |
TakeSnapshot()
Takes and returns a snapshot of the contents of a session at the time of calling.
Declaration
IReadOnlyList<KeyValuePair<string, object>> TakeSnapshot()
Returns
Type | Description |
---|---|
IReadOnlyList<KeyValuePair<String, Object>> | An |
Remarks
The objects contained in the session data are copied by reference, not cloned; therefore you should be aware that their state may change even after the snapshot is taken.
TryGetValue(String, out Object)
Gets the value associated with the specified key.
Declaration
bool TryGetValue(string key, out object value)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key whose value to get. |
Object | value | When this method returns, the value associated with the specified |
Returns
Type | Description |
---|---|
Boolean | true if the object that implements ISession contains an element with the specified key; otherwise, false. |
TryRemove(String, out Object)
Attempts to remove and return the value that has the specified key from a session.
Declaration
bool TryRemove(string key, out object value)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key of the element to remove and return. |
Object | value | When this method returns, the value removed from the object that implements ISession, if the key is found; otherwise, null. This parameter is passed uninitialized. |
Returns
Type | Description |
---|---|
Boolean | true if the value was removed successfully; otherwise, false. |