C# Class PVL.MongoSessionProvider

Custom ASP.NET Session State Provider using MongoDB as the state store. Session state default store: "Sessions" collection within a "SessionState" database. Example session document: { "_id" : "i2guetwsm0mgaibb1gqmodfq", "App" : "/", "Created" : ISODate("2013-02-21T22:27:32.091Z"), "Expires" : ISODate("2013-02-22T22:30:59.267Z"), "LockDate" : ISODate("2013-02-21T22:29:54.481Z"), "LockId" : 1, "Timeout" : 20, "Locked" : true, "Items" : "AQAAAP////8EVGVzdAgAAAABBkFkcmlhbg==", "Flags" : 0 } Scheduled session cleanup: db.Sessions.remove({"Expires" : {$lt : new Date() }}) Example web.config settings: .. ..
Inheritance: System.Web.SessionState.SessionStateStoreProviderBase
Mostra file Open project: prasannavl/MongoSessionProvider

Public Methods

Method Description
CreateNewStoreData ( System context, int timeout ) : System.Web.SessionState.SessionStateStoreData
CreateUninitializedItem ( System context, string id, int timeout ) : void
Dispose ( ) : void
EndRequest ( System context ) : void
GetItem ( HttpContext context, string id, bool &locked, System.TimeSpan &lockAge, object &lockId, SessionStateActions &actionFlags ) : System.Web.SessionState.SessionStateStoreData

SessionStateProviderBase.GetItem

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

SessionStateProviderBase.GetItemExclusive

Initialize ( string name, System config ) : void
InitializeRequest ( System context ) : void
ReleaseItemExclusive ( System context, string id, object lockId ) : void
RemoveItem ( System context, string id, object lockId, System.Web.SessionState.SessionStateStoreData item ) : void
ResetItemTimeout ( System context, string id ) : void
SetAndReleaseItemExclusive ( HttpContext context, string id, System.Web.SessionState.SessionStateStoreData item, object lockId, bool newItem ) : void

SessionStateProviderBase.SetAndReleaseItemExclusive

SetItemExpireCallback ( SessionStateItemExpireCallback expireCallback ) : bool

Private Methods

Method Description
Deserialize ( HttpContext context, string serializedItems, int timeout ) : System.Web.SessionState.SessionStateStoreData
GetSessionCollection ( ) : MongoCollection
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.

Serialize ( System.Web.SessionState.SessionStateItemCollection items ) : string

Serialize is called by the SetAndReleaseItemExclusive method to convert the SessionStateItemCollection into a Base64 string to be stored in MongoDB.

WriteToEventLog ( Exception e, string action ) : void

This is a helper function that writes exception detail to the event log. Exceptions are written to the event log as a security measure to ensure private database details are not returned to browser. If a method does not return a status or Boolean indicating the action succeeded or failed, the caller also throws a generic exception.

Method Details

CreateNewStoreData() public method

public CreateNewStoreData ( System context, int timeout ) : System.Web.SessionState.SessionStateStoreData
context System
timeout int
return System.Web.SessionState.SessionStateStoreData

CreateUninitializedItem() public method

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

Dispose() public method

public Dispose ( ) : void
return void

EndRequest() public method

public EndRequest ( System context ) : void
context System
return void

GetItem() public method

SessionStateProviderBase.GetItem
public GetItem ( HttpContext context, string id, bool &locked, System.TimeSpan &lockAge, object &lockId, SessionStateActions &actionFlags ) : System.Web.SessionState.SessionStateStoreData
context System.Web.HttpContext
id string
locked bool
lockAge System.TimeSpan
lockId object
actionFlags SessionStateActions
return System.Web.SessionState.SessionStateStoreData

GetItemExclusive() public method

SessionStateProviderBase.GetItemExclusive
public GetItemExclusive ( HttpContext context, string id, bool &locked, System.TimeSpan &lockAge, object &lockId, SessionStateActions &actionFlags ) : System.Web.SessionState.SessionStateStoreData
context System.Web.HttpContext
id string
locked bool
lockAge System.TimeSpan
lockId object
actionFlags SessionStateActions
return System.Web.SessionState.SessionStateStoreData

Initialize() public method

public Initialize ( string name, System config ) : void
name string
config System
return void

InitializeRequest() public method

public InitializeRequest ( System context ) : void
context System
return void

ReleaseItemExclusive() public method

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

RemoveItem() public method

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

ResetItemTimeout() public method

public ResetItemTimeout ( System context, string id ) : void
context System
id string
return void

SetAndReleaseItemExclusive() public method

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

SetItemExpireCallback() public method

public SetItemExpireCallback ( SessionStateItemExpireCallback expireCallback ) : bool
expireCallback SessionStateItemExpireCallback
return bool