C# Class MySql.Web.SessionState.MySqlSessionStateStore

This class allows ASP.NET applications to store and manage session state information in a MySQL database. Expired session data is periodically deleted from the database.
Inheritance: System.Web.SessionState.SessionStateStoreProviderBase
Mostrar archivo Open project: elevate/mysqlconnector-.net Class Usage Examples

Private Properties

Property Type Description
CheckStorageEngine void
CleanupOldSessions void
Deserialize System.Web.SessionState.SessionStateStoreData
GetCleanupInterval int
GetSessionStoreItem System.Web.SessionState.SessionStateStoreData
HandleMySqlException void
Serialize byte[]

Public Methods

Method Description
CreateNewStoreData ( System context, int timeout ) : System.Web.SessionState.SessionStateStoreData

This method creates a new SessionStateStoreData object for the current request.

CreateUninitializedItem ( System context, string id, int timeout ) : void

This method adds a new session state item to the database.

Dispose ( ) : void

This method releases all the resources for this instance.

EndRequest ( System context ) : void

This method allows the MySqlSessionStateStore object to perform any cleanup that may be required for the current request.

GetItem ( System context, string id, bool &locked, System.TimeSpan &lockAge, object &lockId, SessionStateActions &actions ) : System.Web.SessionState.SessionStateStoreData

This method returns a read-only session item from the database.

GetItemExclusive ( System context, string id, bool &locked, System.TimeSpan &lockAge, object &lockId, SessionStateActions &actions ) : System.Web.SessionState.SessionStateStoreData

This method locks a session item and returns it from the database

Initialize ( string name, NameValueCollection config ) : void

Initializes the provider with the property values specified in the ASP.NET application configuration file

InitializeRequest ( System context ) : void

This method performs any per-request initializations that the MySqlSessionStateStore provider requires.

ReleaseItemExclusive ( System context, string id, object lockId ) : void

This method forcibly releases the lock on a session item in the database, if multiple attempts to retrieve the session item fail.

RemoveItem ( System context, string id, object lockId, System.Web.SessionState.SessionStateStoreData item ) : void

This method removes the specified session item from the database

ResetItemTimeout ( System context, string id ) : void

This method resets the expiration date and timeout for a session item in the database.

SetAndReleaseItemExclusive ( System context, string id, System.Web.SessionState.SessionStateStoreData item, object lockId, bool newItem ) : void

This method updates the session time information in the database with the specified session item, and releases the lock.

SetItemExpireCallback ( SessionStateItemExpireCallback expireCallback ) : bool

This method returns a false value to indicate that callbacks for expired sessions are not supported.

Private Methods

Method Description
CheckStorageEngine ( MySqlConnection con ) : void

Check storage engine used by my_aspnet_Sessions. Warn if MyISAM is used - it does not handle concurrent updates well which is important for session provider, as each access to session does an update to "expires" field.

CleanupOldSessions ( object o ) : void
Deserialize ( HttpContext context, byte serializedItems, int timeout ) : System.Web.SessionState.SessionStateStoreData

Deserialize is called by the GetSessionStoreItem method to convert the byte array stored in the blob field to a SessionStateItemCollection.

GetCleanupInterval ( MySqlConnection con ) : int
GetSessionStoreItem ( bool lockRecord, HttpContext context, string id, bool &locked, System.TimeSpan &lockAge, object &lockId, SessionStateActions &actionFlags ) : System.Web.SessionState.SessionStateStoreData

GetSessionStoreItem is called by both the GetItem and GetItemExclusive methods. GetSessionStoreItem retrieves the session data from the data source. If the lockRecord parameter is true (in the case of GetItemExclusive), then GetSessionStoreItem locks the record and sets a New LockId and LockDate.

HandleMySqlException ( MySql.Data.MySqlClient.MySqlException e, string action ) : void

Handles MySql exception. If WriteExceptionsToEventLog is set, will write exception info to event log. It throws provider exception (original exception is stored as inner exception)

Serialize ( System.Web.SessionState.SessionStateItemCollection items ) : byte[]

Serialize is called by the SetAndReleaseItemExclusive method to convert the SessionStateItemCollection into a byte array to be stored in the blob field.

Method Details

CreateNewStoreData() public method

This method creates a new SessionStateStoreData object for the current request.
public CreateNewStoreData ( System context, int timeout ) : System.Web.SessionState.SessionStateStoreData
context System /// The HttpContext object for the current request. ///
timeout int /// The timeout value (in minutes) for the SessionStateStoreData object that is created. ///
return System.Web.SessionState.SessionStateStoreData

CreateUninitializedItem() public method

This method adds a new session state item to the database.
public CreateUninitializedItem ( System context, string id, int timeout ) : void
context System /// The HttpContext object for the current request. ///
id string /// The session ID for the current request. ///
timeout int /// The timeout value for the current request. ///
return void

Dispose() public method

This method releases all the resources for this instance.
public Dispose ( ) : void
return void

EndRequest() public method

This method allows the MySqlSessionStateStore object to perform any cleanup that may be required for the current request.
public EndRequest ( System context ) : void
context System The HttpContext object for the current request
return void

GetItem() public method

This method returns a read-only session item from the database.
public GetItem ( System context, string id, bool &locked, System.TimeSpan &lockAge, object &lockId, SessionStateActions &actions ) : System.Web.SessionState.SessionStateStoreData
context System
id string
locked bool
lockAge System.TimeSpan
lockId object
actions SessionStateActions
return System.Web.SessionState.SessionStateStoreData

GetItemExclusive() public method

This method locks a session item and returns it from the database
public GetItemExclusive ( System context, string id, bool &locked, System.TimeSpan &lockAge, object &lockId, SessionStateActions &actions ) : System.Web.SessionState.SessionStateStoreData
context System The HttpContext object for the current request
id string The session ID for the current request
locked bool /// true if the session item is locked in the database; otherwise, it is false. ///
lockAge System.TimeSpan /// TimeSpan object that indicates the amount of time the session item has been locked in the database. ///
lockId object /// A lock identifier object. ///
actions SessionStateActions /// A SessionStateActions enumeration value that indicates whether or /// not the session is uninitialized and cookieless. ///
return System.Web.SessionState.SessionStateStoreData

Initialize() public method

Initializes the provider with the property values specified in the ASP.NET application configuration file
public Initialize ( string name, NameValueCollection config ) : void
name string The name of the provider instance to initialize.
config System.Collections.Specialized.NameValueCollection Object that contains the names and values of configuration options for the provider. ///
return void

InitializeRequest() public method

This method performs any per-request initializations that the MySqlSessionStateStore provider requires.
public InitializeRequest ( System context ) : void
context System
return void

ReleaseItemExclusive() public method

This method forcibly releases the lock on a session item in the database, if multiple attempts to retrieve the session item fail.
public ReleaseItemExclusive ( System context, string id, object lockId ) : void
context System The HttpContext object for the current request.
id string The session ID for the current request.
lockId object The lock identifier for the current request.
return void

RemoveItem() public method

This method removes the specified session item from the database
public RemoveItem ( System context, string id, object lockId, System.Web.SessionState.SessionStateStoreData item ) : void
context System The HttpContext object for the current request
id string The session ID for the current request
lockId object The lock identifier for the current request.
item System.Web.SessionState.SessionStateStoreData The session item to remove from the database.
return void

ResetItemTimeout() public method

This method resets the expiration date and timeout for a session item in the database.
public ResetItemTimeout ( System context, string id ) : void
context System The HttpContext object for the current request
id string The session ID for the current request
return void

SetAndReleaseItemExclusive() public method

This method updates the session time information in the database with the specified session item, and releases the lock.
public SetAndReleaseItemExclusive ( System context, string id, System.Web.SessionState.SessionStateStoreData item, object lockId, bool newItem ) : void
context System The HttpContext object for the current request
id string The session ID for the current request
item System.Web.SessionState.SessionStateStoreData The session item containing new values to update the session item in the database with. ///
lockId object The lock identifier for the current request.
newItem bool A Boolean value that indicates whether or not the session item is new in the database. /// A false value indicates an existing item. ///
return void

SetItemExpireCallback() public method

This method returns a false value to indicate that callbacks for expired sessions are not supported.
public SetItemExpireCallback ( SessionStateItemExpireCallback expireCallback ) : bool
expireCallback SessionStateItemExpireCallback
return bool