DynamoDBSessionStateStore is a custom session state provider that can be used inside of an ASP.NET application. Session state is saved
inside a DynamoDB table that can be configured in the web.config. If the table does not exist the provider will create
it during initialization with default read and write units set to 10 and 5 unless configured otherwise. If the table is created
the application startup will block for about a minute while the table is being created.
Example web.config entry setting up the session state provider.
CopyC#
<sessionState mode="Custom" customProvider="DynamoDBSessionStoreProvider"gt; <providers> <add name="DynamoDBSessionStoreProvider" type="Amazon.SessionProvider.DynamoDBSessionStateStore" AWSAccessKey="YOUR_ACCESS_KEY" AWSSecretKey="YOUR_SECRET_KEY" Region="us-east-1" Table="ASP.NET_SessionState" /> </providers> </sessionState>
The schema for the table used to store session requires a string hash key with no range key. The provider will look up the name of the hash key during initialization so any name can be given for the hash key.
Below is a list of configuration attributes that can specified in the provider element in the web.config.
Config Constant | Use |
---|---|
AWSAccessKey | Access key used. This can be set at either the provider or in the appSettings. |
AWSSecretKey | Secret key used. This can be set at either the provider or in the appSettings. |
Region | Required string attribute. The region to use DynamoDB in. The default is us-east-1. Possible values are us-east-1, us-west-1, us-west-2, eu-west-1, ap-northeast-1, ap-southeast-1. |
Application | Optional string attribute. Application is used to partition the session data in the table so it can be used for more than one application. |
Table | Optional string attribute. The table used to store session data. The default is ASP.NET_SessionState. |
ReadCapacityUnits | Optional int attribute. The read capacity units if the table is created. The default is 10. |
WriteCapacityUnits | Optional int attribute. The write capacity units if the table is created. The default is 5. |
CreateIfNotExist | Optional boolean attribute. CreateIfNotExist controls whether the table will be auto created if it doesn't exist. Default is true. |
Declaration Syntax
C# |
public class DynamoDBSessionStateStore : SessionStateStoreProviderBase
Members
All Members | Constructors | Methods | Properties | Fields | |
Icon | Member | Description |
---|---|---|
DynamoDBSessionStateStore()()()() |
Default Constructor
| |
DynamoDBSessionStateStore(AmazonDynamoDB) |
Constructor for testing.
| |
DynamoDBSessionStateStore(String, NameValueCollection) |
Constructor for testing.
| |
ATTRIBUTE_CREATE_DATE | ||
ATTRIBUTE_EXPIRES | ||
ATTRIBUTE_FLAGS | ||
ATTRIBUTE_LOCK_DATE | ||
ATTRIBUTE_LOCK_ID | ||
ATTRIBUTE_LOCKED | ||
ATTRIBUTE_RECORD_FORMAT_VERSION | ||
ATTRIBUTE_SESSION_ITEMS | ||
CONFIG_ACCESSKEY | ||
CONFIG_APPLICATION | ||
CONFIG_CREATE_TABLE_IF_NOT_EXIST | ||
CONFIG_INITIAL_READ_UNITS | ||
CONFIG_INITIAL_WRITE_UNITS | ||
CONFIG_REGION | ||
CONFIG_SECRETKEY | ||
CONFIG_TABLE | ||
CreateNewStoreData(HttpContext, Int32) |
Creates a new SessionStateStoreData object to be used for the current request.
(Overrides SessionStateStoreProviderBase.CreateNewStoreData(HttpContext, Int32).) | |
CreateUninitializedItem(HttpContext, String, Int32) |
Creates an initial session record in the DynamoDB table.
(Overrides SessionStateStoreProviderBase.CreateUninitializedItem(HttpContext, String, Int32).) | |
DeleteExpiredSessions(AmazonDynamoDB) |
A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the ASP.NET_SessionState table
with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance
so use this method sparingly like a nightly or weekly clean job.
| |
DeleteExpiredSessions(AmazonDynamoDB, String) |
A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the table
with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance
so use this method sparingly like a nightly or weekly clean job.
| |
Description | Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs). (Inherited from ProviderBase.) | |
Dispose()()()() |
Empty implementation of the override.
(Overrides SessionStateStoreProviderBase.Dispose()()()().) | |
EndRequest(HttpContext) |
Empty implementation of the override.
(Overrides SessionStateStoreProviderBase.EndRequest(HttpContext).) | |
Equals(Object) | (Inherited from Object.) | |
GetHashCode()()()() | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetItem(HttpContext, String, Boolean%, TimeSpan%, Object%, SessionStateActions%) |
Returns read-only session-state data from the DynamoDB table.
(Overrides SessionStateStoreProviderBase.GetItem(HttpContext, String, Boolean%, TimeSpan%, Object%, SessionStateActions%).) | |
GetItemExclusive(HttpContext, String, Boolean%, TimeSpan%, Object%, SessionStateActions%) |
Returns session-state data from the DynamoDB table.
(Overrides SessionStateStoreProviderBase.GetItemExclusive(HttpContext, String, Boolean%, TimeSpan%, Object%, SessionStateActions%).) | |
GetType()()()() | Gets the type of the current instance. (Inherited from Object.) | |
Initialize(String, NameValueCollection) |
Initializes the provider by pulling the config info from the web.config and validate/create the DynamoDB table.
If the table is being created this method will block until the table is active.
(Overrides ProviderBase.Initialize(String, NameValueCollection).) | |
InitializeRequest(HttpContext) |
Empty implementation of the override.
(Overrides SessionStateStoreProviderBase.InitializeRequest(HttpContext).) | |
Name | Gets the friendly name used to refer to the provider during configuration. (Inherited from ProviderBase.) | |
ReleaseItemExclusive(HttpContext, String, Object) |
Releases a lock on an item in the session data store.
(Overrides SessionStateStoreProviderBase.ReleaseItemExclusive(HttpContext, String, Object).) | |
RemoveItem(HttpContext, String, Object, SessionStateStoreData) |
Removes the session record for DynamoDB.
(Overrides SessionStateStoreProviderBase.RemoveItem(HttpContext, String, Object, SessionStateStoreData).) | |
ResetItemTimeout(HttpContext, String) |
Updates the expiration date and time of an item in the DynamoDB table.
(Overrides SessionStateStoreProviderBase.ResetItemTimeout(HttpContext, String).) | |
SetAndReleaseItemExclusive(HttpContext, String, SessionStateStoreData, Object, Boolean) |
Updates the session-item information in the session-state data store with values from the current request, and clears the lock on the data.
(Overrides SessionStateStoreProviderBase.SetAndReleaseItemExclusive(HttpContext, String, SessionStateStoreData, Object, Boolean).) | |
SetItemExpireCallback(SessionStateItemExpireCallback) |
Provider returns false for this method.
(Overrides SessionStateStoreProviderBase.SetItemExpireCallback(SessionStateItemExpireCallback).) | |
TableName |
Gets the name of the table used to store session data.
| |
ToString()()()() | Returns a string that represents the current object. (Inherited from Object.) |
Inheritance Hierarchy
Object | |||
ProviderBase | |||
SessionStateStoreProviderBase | |||
DynamoDBSessionStateStore |