SessionPageStatePersister Class


在 Web 服务器上存储 ASP.NET 页视图状态。Stores ASP.NET page view state on the Web server.

public ref class SessionPageStatePersister : System::Web::UI::PageStatePersister
public class SessionPageStatePersister : System.Web.UI.PageStatePersister
type SessionPageStatePersister = class
    inherit PageStatePersister
Public Class SessionPageStatePersister
Inherits PageStatePersister


下面的代码示例演示如何编写一个 PageAdapter 类来返回 SessionPageStatePersister 类的实例,而不是使用默认的 HiddenFieldPageStatePersister 类将视图状态保存到服务器端会话对象。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.

namespace Samples.AspNet.CS {

    using System.Web.UI;

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

        public override PageStatePersister GetStatePersister() {
            return new SessionPageStatePersister(Page);
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

End Namespace


ASP.NET 页可以将 Page 状态信息存储在本质上无状态 HTTP 请求和处理和服务任何网页所需的响应之间。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."

默认的 ASP.NET 持久性机制是使用 HiddenFieldPageStatePersister 类在客户端上存储视图状态。The default ASP.NET persistence mechanism is to store view state on the client using the HiddenFieldPageStatePersister class. 在一般情况下,使用每个 HTTP 请求和响应来存储视图状态和数据会很好地执行,并且在大型 Web 场方案中非常重要,因为请求的 Web 服务器不重要:页面状态在服务器的当前上下文中可用。准确渲染页面。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. 多个 ASP.NET 设备页面适配器会重写 GetStatePersister 方法,以返回一个 SessionPageStatePersister 对象,该对象在与客户端关联的 session 对象中存储页面状态。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.



初始化 SessionPageStatePersister 类的新实例。Initializes a new instance of the SessionPageStatePersister class.



获取或设置一个对象,该对象表示当前 Page 对象包含的控件用于跨 Web 服务器的 HTTP 请求保留的数据。Gets or sets an object that represents the data that controls contained by the current Page object use to persist across HTTP requests to the Web server.

(Inherited from PageStatePersister)

获取或设置为其创建视图状态持久性机制的 Page 对象。Gets or sets the Page object that the view state persistence mechanism is created for.

(Inherited from PageStatePersister)

获取一个 IStateFormatter 对象,该对象在对 ViewStateControlState 方法的调用期间用于对包含在 Save()Load() 属性中的状态信息进行序列化和反序列化。Gets an IStateFormatter object that is used to serialize and deserialize the state information contained in the ViewState and ControlState properties during calls to the Save() and Load() methods.

(Inherited from PageStatePersister)

获取或设置一个对象,该对象表示当前 Page 对象包含的控件用于跨 Web 服务器的 HTTP 请求保留的数据。Gets or sets an object that represents the data that controls contained by the current Page object use to persist across HTTP requests to the Web server.

(Inherited from PageStatePersister)



确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)

Page 对象对其控件层次结构进行初始化时,对服务器端会话对象中保存的状态进行反序列化并加载该状态。Deserializes and loads persisted state from the server-side session object when a Page object initializes its control hierarchy.


创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)

ViewStateControlState 属性中包含的任何对象状态进行序列化,并将该状态写入会话对象。Serializes any object state contained in the ViewState or the ControlState property and writes the state to the session object.


返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also