SessionStateStoreProviderBase 类

定义

定义数据存储区的会话状态提供程序所需的成员。Defines the required members of a session-state provider for a data store.

public ref class SessionStateStoreProviderBase abstract : System::Configuration::Provider::ProviderBase
public abstract class SessionStateStoreProviderBase : System.Configuration.Provider.ProviderBase
type SessionStateStoreProviderBase = class
    inherit ProviderBase
Public MustInherit Class SessionStateStoreProviderBase
Inherits ProviderBase
继承
SessionStateStoreProviderBase

示例

有关会话状态存储提供程序实现的示例,请参阅实现会话状态存储提供程序For an example of a session-state store provider implementation, see Implementing a Session-State Store Provider.

下面的代码示例显示了配置为使用自定义会话状态存储提供程序的 ASP.NET 应用程序的 web.config 文件。The following code example shows the Web.config file for an ASP.NET application that is configured to use a custom session-state store provider.

<configuration>  
  <connectionStrings>  
    <add name="OdbcSessionServices" connectionString="DSN=SessionState;" />  
  </connectionStrings>  
  
  <system.web>  
    <sessionState   
      mode="Custom"  
      customProvider="OdbcSessionProvider">  
      <providers>  
        <add name="OdbcSessionProvider"  
             type="Samples.AspNet.Session.OdbcSessionStateStore"  
             connectionStringName="OdbcSessionServices" />  
      </providers>  
    </sessionState>  
  </system.web>  
</configuration>  

注解

ASP.NET 会话状态使用会话状态存储提供程序从数据存储区读取会话数据并将其写入数据存储区。ASP.NET session state reads and writes session data from and to a data store using a session-state store provider. 会话状态存储提供程序是继承SessionStateStoreProviderBase抽象类的类,并使用特定于数据存储的实现替代其成员。A session-state store provider is a class that inherits the SessionStateStoreProviderBase abstract class and overrides its members with implementations specific to the data store. 会话状态存储提供程序在处理 ASP.NET 页期间SessionStateModule由类调用,以与用于存储和检索会话变量的数据存储区和相关会话信息(如超时值)进行通信。The session-state store provider is called by the SessionStateModule class during the processing of an ASP.NET page to communicate with the data store for the storage and retrieval of session variables and related session information such as the time-out value.

每个 ASP.NET 应用程序中的会话数据分别存储SessionID在每个属性中。Session data within each ASP.NET application is stored separately for each SessionID property. ASP.NET 应用程序不共享会话数据。ASP.NET applications do not share session data.

SessionStateStoreProviderBase可以通过sessionState Custom将配置元素的customProvider属性设置为,并将属性设置为自定义提供程序的名称,来指定 ASP.NET 应用程序的自定义实现,如mode本主题的示例中所示。You can specify a custom SessionStateStoreProviderBase implementation for an ASP.NET application by setting the mode attribute of the sessionState configuration element to Custom and the customProvider attribute to the name of the custom provider, as shown in the example for this topic.

锁定会话存储数据Locking Session Store Data

由于 ASP.NET 应用程序可进行多线程处理以支持响应并发请求,因此并发请求可能会尝试访问相同的会话信息。Because ASP.NET applications are multithreaded to support responding to concurrent requests, it is possible that concurrent requests might attempt to access the same session information. 请考虑这样一种情况:框架集中的多个框架都访问同一应用程序。Consider a scenario where multiple frames in a frameset all access the same application. 可以在不同的线程上同时在 Web 服务器上对框架集中的每个帧执行单独的请求。The separate requests for each frame in the frameset can be executed on the Web server concurrently on different threads. 如果每个帧源访问会话状态变量的 ASP.NET 页,则可以有多个线程并发访问会话存储。If the ASP.NET pages for each frame source access session-state variables, then you could have multiple threads accessing the session store concurrently.

为了避免会话存储区中的数据冲突和意外的会话状态行为, SessionStateModuleSessionStateStoreProviderBase类包括了锁定功能,以独占方式锁定特定会话的会话存储项执行 ASP.NET 页。To avoid data collisions at the session store and unexpected session-state behavior, the SessionStateModule and SessionStateStoreProviderBase classes include lock functionality that exclusively locks the session store item for a particular session for the duration of the execution of an ASP.NET page. 请注意,即使将EnableSessionState属性标记为ReadOnly,同一应用程序中的其他 ASP.NET 页也可能能够写入会话存储,因此,来自存储的只读会话数据的请求可能仍会等待锁定的数据被解脱.Note that even if the EnableSessionState attribute is marked as ReadOnly, other ASP.NET pages in the same application might be able to write to the session store, so a request for read-only session data from the store might still end up waiting for locked data to be freed.

在请求开始时,在调用GetItemExclusive方法时对会话存储数据设置锁。A lock is set on session-store data at the beginning of the request, in the call to the GetItemExclusive method. 请求完成后,会在调用SetAndReleaseItemExclusive方法的过程中释放锁。When the request completes, the lock is released during the call to the SetAndReleaseItemExclusive method.

如果对象在调用GetItemExclusiveGetItem方法的过程中遇到锁定的会话数据,它将以半秒的间隔重新请求会话数据,直到锁定被释放或SessionStateModule会话数据已锁定超出了ExecutionTimeout属性的值。If the SessionStateModule object encounters locked session data during the call to either the GetItemExclusive or the GetItem method, it will re-request the session data at half-second intervals until either the lock is released or the amount of time that the session data has been locked exceeds the value of the ExecutionTimeout property. 如果超过了执行超时时间,则SessionStateModule对象将ReleaseItemExclusive调用方法来释放会话存储数据,并在此时请求会话存储数据。If the execution time out is exceeded, the SessionStateModule object will call the ReleaseItemExclusive method to free the session-store data and request the session-store data at that time.

由于锁定的会话存储数据可能已在调用ReleaseItemExclusive SetAndReleaseItemExclusive当前响应的方法之前,通过在单独的线程上调用方法来释放,因此可能会尝试设置和释放会话状态存储数据,这些数据具有已由另一个会话发布和修改。Because locked session-store data might have been freed by a call to the ReleaseItemExclusive method on a separate thread before the call to the SetAndReleaseItemExclusive method for the current response, an attempt could be made to set and release session-state store data that has already been released and modified by another session. 若要避免这种情况GetItemGetItemExclusive和方法将返回一个锁标识符。To avoid this situation, the GetItem and GetItemExclusive methods return a lock identifier. 此锁定标识符必须包含在每个请求中以修改锁定的会话存储数据。This lock identifier must be included with each request to modify locked session-store data. 仅当数据存储区中的锁标识符与所SessionStateModule提供的锁标识符相匹配时,才会修改会话存储数据。Session-store data is modified only if the lock identifier in the data store matches the lock identifier supplied by the SessionStateModule.

删除过期的会话存储数据Deleting Expired Session Store Data

如果为特定会话调用了RemoveItem 方法,则使用方法从数据存储区中删除该会话的数据;否则,数据将保留在会话数据存储中,以便为该会话提供服务器未来的请求。AbandonWhen the Abandon method is called for a particular session, the data for that session is deleted from the data store using the RemoveItem method; otherwise, the data will remain in the session data store to server future requests for the session. 这是SessionStateStoreProviderBase由实现来删除过期的会话数据的。It is up to the SessionStateStoreProviderBase implementation to delete expired session data.

构造函数

SessionStateStoreProviderBase()

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

属性

Description

获取一条简短的易懂描述,它适合在管理工具或其他用户界面 (UI) 中显示。Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(继承自 ProviderBase)
Name

获得一个友好名称,用于在配置过程中引用提供程序。Gets the friendly name used to refer to the provider during configuration.

(继承自 ProviderBase)

方法

CreateNewStoreData(HttpContext, Int32)

创建要用于当前请求的新 SessionStateStoreData 对象。Creates a new SessionStateStoreData object to be used for the current request.

CreateUninitializedItem(HttpContext, String, Int32)

将新的会话状态项添加到数据存储区中。Adds a new session-state item to the data store.

Dispose()

释放由 SessionStateStoreProviderBase 实现使用的所有资源。Releases all resources used by the SessionStateStoreProviderBase implementation.

EndRequest(HttpContext)

在请求结束时由 SessionStateModule 对象调用。Called by the SessionStateModule object at the end of a request.

Equals(Object)

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

(继承自 Object)
GetHashCode()

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

(继承自 Object)
GetItem(HttpContext, String, Boolean, TimeSpan, Object, SessionStateActions)

从会话数据存储区中返回只读会话状态数据。Returns read-only session-state data from the session data store.

GetItemExclusive(HttpContext, String, Boolean, TimeSpan, Object, SessionStateActions)

从会话数据存储区中返回只读会话状态数据。Returns read-only session-state data from the session data store.

GetType()

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

(继承自 Object)
Initialize(String, NameValueCollection)

初始化配置生成器。Initializes the configuration builder.

(继承自 ProviderBase)
InitializeRequest(HttpContext)

SessionStateModule 对象调用,以便进行每次请求初始化。Called by the SessionStateModule object for per-request initialization.

MemberwiseClone()

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

(继承自 Object)
ReleaseItemExclusive(HttpContext, String, Object)

释放对会话数据存储区中项的锁定。Releases a lock on an item in the session data store.

RemoveItem(HttpContext, String, Object, SessionStateStoreData)

删除会话数据存储区中的项数据。Deletes item data from the session data store.

ResetItemTimeout(HttpContext, String)

更新会话数据存储区中的项的到期日期和时间。Updates the expiration date and time of an item in the session data store.

SetAndReleaseItemExclusive(HttpContext, String, SessionStateStoreData, Object, Boolean)

使用当前请求中的值更新会话状态数据存储区中的会话项信息,并清除对数据的锁定。Updates the session-item information in the session-state data store with values from the current request, and clears the lock on the data.

SetItemExpireCallback(SessionStateItemExpireCallback)

设置对 Global.asax 文件中定义的 Session_OnEnd 事件的 SessionStateItemExpireCallback 委托的引用。Sets a reference to the SessionStateItemExpireCallback delegate for the Session_OnEnd event defined in the Global.asax file.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅