PersistDemo.PagePersister Class
Page persistence handling object. Walks the declared instance or static fields of a System.Web.UI.Page object and saves or restores field values for fields decorated with a PagePersistAttribute. Generally, instance fields are persisted using the Session property bag and static fields are persisted using the Application property bag. Note that static fields of ANY class can be persisted using the Application or web.config files. Only "page" classes can request persistence of instance fields, since that mechanism uses the Session object.

Access: Public
Base Classes: Object
  Members Description  
    PagePersister Construct a PagePersister for a given page.

 
    PagePersister Construct a page persister for static fields of the given type.

 
    Save Save instance fields to persistence medium

 
    Restore Restore instance fields from persistence medium

 
    SaveStatic Save static fields to persistence medium

 
    RestoreStatic Restore static fields from persistence medium

 
    RestoreStatic Restore persistent static fields for the given class (by type)

 
    RestorePageStatics Search for all subclasses of System.Web.UI.Page and restore static fields to each Page class.

 
    SetPageField Prepare the application's dictionary so that the value of a page's static field will be set to a particular value when its static fields are restored.

 
    SetPageField Prepare the application's dictionary so that the value of a page's static field will be set to a particular value when its static fields are restored.

 
    SetPageField Set the persistent value of a persisted page field.

 
    SetPageField Set the persistent value of a persisted page field.

 
    Action Worker function for persistence: saves or loads static or instance field values.

 
    PersistPage Perform page-level persistence for the newly-created or about-to-be-released page

 
    SessionEnd Clean up any persisted field values from this session's state collection. That is, call IDisposable.Dispose() on any objects that support it.

 
    VarName Generate a string name to use as a key for a persistence data collection. For Session data, the field key is "$persist$classTypeName$fieldName". For Application data, the field key is "$persist$classTypeName$fieldName". For Web Config data, the field key is "$persist$fieldName".

 
    VarName Generate a string name to use as a key for a persistence data collection. For Session data, the field key is "$persist$classTypeName$fieldName". For Application data, the field key is "$persist$classTypeName$fieldName". For Web Config data, the field key is "$persist$fieldName".

 
    sPrefixDelimiter Delimiter character used between key name components

 
    sPrefixSession String prefix to use for session fields (along with type and field name)

 
    sPrefixApplication String prefix to use for session fields (along with type and field name)

 
    sPrefixConfiguration String prefix to use for web.config fields (along with field name)

 
    app The web application for this operation

 
    page The page, if any, for this operation

 
    type The type of page or object being operated on.

 
    bindFlagsInstance The type information binding flags used for walking the instance fields.

 
    bindFlagsStatic The type information binding flags used for walking the static fields

 
Remarks:
As the code is currently written, persistence can be applied only to protected fields. There are two types of fields: static (class-level or "shared") and object-level. There are three persistence media: the Application dictionary, the Session dictionary and the appSesstings tag in the project's web.config file. This leads to six possible combinations of field and media. In each case, there is a mapping between the field name you chose and the key used in the relevant dictionary. Some media are read-only, others are read-write. Basically, any class can have its static members initialized, but only subclasses of System.Web.UI.Page can have object-level fields persisted at the session level.

Implications of each combination of field type and storage medium are as follows.

Object field, Session storage: Allowed, save and restore. Object must inherit from System.Web.UI.Page. Key is $persist$typeName$fieldName.

Object field, Application storage: Allowed, save and restore. Object must inherit from System.Web.UI.Page. Key is $persist$typeName$fieldName.

Object field, Configuration storage: Allowed, but restore only. Object must inherit from System.Web.UI.Page. Key is $persist$fieldName.

Static field, Session storage: NOT ALLOWED.

Static field, Application storage: Allowed, save and restore. Key is $persist$typeName$fieldName.

Static field, Configuration storage: Allowed, restore only. Key is $persist$typeName$fieldName.