Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
SessionPageStatePersister Class

Updated: November 2007

Stores ASP.NET page view state on the Web server.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class SessionPageStatePersister _
    Inherits PageStatePersister
Visual Basic (Usage)
Dim instance As SessionPageStatePersister
C#
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class SessionPageStatePersister : PageStatePersister
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class SessionPageStatePersister : public PageStatePersister
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class SessionPageStatePersister extends PageStatePersister
JScript
public class SessionPageStatePersister extends PageStatePersister

ASP.NET pages can store Page state information between the inherently stateless HTTP request and response required to process and serve any Web page. This state is called "view state."

The default ASP.NET persistence mechanism is to store view state on the client using the HiddenFieldPageStatePersister class. Storing view state and data with each HTTP request and response performs well in general and is important in large Web farm scenarios because it does not matter which Web server services the request: the page state is available in the current context for the server to accurately render the page.

In scenarios where pages are served to small devices that have limited client-side resources or use a markup language that does not support a hidden field element, it is required to store view state on the server. Several ASP.NET device page adapters override the GetStatePersister method to return a SessionPageStatePersister object that stores page state on the server in the session object associated with the client.

The following code example demonstrates how you can write a PageAdapter class to return an instance of the SessionPageStatePersister class instead of the default HiddenFieldPageStatePersister class to save view state to the server-side session object.

Visual Basic
Imports System.Web.UI

Namespace Samples.AspNet.VB

    Public Class MyPageAdapter
       Inherits System.Web.UI.Adapters.PageAdapter


       Public Overrides Function GetStatePersister() As PageStatePersister
          Return New SessionPageStatePersister(Page)
       End Function 'GetStatePersister

    End Class 'MyPageAdapter

End Namespace

C#
namespace Samples.AspNet.CS {

    using System.Web.UI;

    public class MyPageAdapter : System.Web.UI.Adapters.PageAdapter {

        public override PageStatePersister GetStatePersister() {
            return new SessionPageStatePersister(Page);
        }
    }
}

J#
package Samples.AspNet.JSL;

import System.Web.UI.*;

public class MyPageAdapter extends System.Web.UI.Adapters.PageAdapter
{
    public PageStatePersister GetStatePersister()
    {
        return new SessionPageStatePersister(this.get_Page());
    } //GetStatePersister
} //MyPageAdapter

System..::.Object
  System.Web.UI..::.PageStatePersister
    System.Web.UI..::.SessionPageStatePersister
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
A Better Example      Andrew Cupper   |   Edit   |  


I'd suggest that the following C# code should be used instead of the example provided, since ControlState will be lost if SessionPageStatePersister is created multiple times.

    PageStatePersister _pers;
protected override PageStatePersister PageStatePersister
{
get
{
if (_pers == null)
_pers = new SessionPageStatePersister(this);
return _pers;
}
}
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker