SessionStateStoreProviderBase.GetItemExclusive(HttpContext, String, Boolean, TimeSpan, Object, SessionStateActions) 方法

定义

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

public:
 abstract System::Web::SessionState::SessionStateStoreData ^ GetItemExclusive(System::Web::HttpContext ^ context, System::String ^ id, [Runtime::InteropServices::Out] bool % locked, [Runtime::InteropServices::Out] TimeSpan % lockAge, [Runtime::InteropServices::Out] System::Object ^ % lockId, [Runtime::InteropServices::Out] System::Web::SessionState::SessionStateActions % actions);
public abstract System.Web.SessionState.SessionStateStoreData GetItemExclusive (System.Web.HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out System.Web.SessionState.SessionStateActions actions);
abstract member GetItemExclusive : System.Web.HttpContext * string * bool * TimeSpan * obj * SessionStateActions -> System.Web.SessionState.SessionStateStoreData
Public MustOverride Function GetItemExclusive (context As HttpContext, id As String, ByRef locked As Boolean, ByRef lockAge As TimeSpan, ByRef lockId As Object, ByRef actions As SessionStateActions) As SessionStateStoreData

参数

context
HttpContext

当前请求的 HttpContextThe HttpContext for the current request.

id
String

当前请求的 SessionIDThe SessionID for the current request.

locked
Boolean

当此方法返回时,如果成功获得锁定,请包含一个设置为 true 的布尔值;否则请包含一个设置为 false 的布尔值。When this method returns, contains a Boolean value that is set to true if a lock is successfully obtained; otherwise, false.

lockAge
TimeSpan

当此方法返回时,请包含一个设置为会话数据存储区中的项锁定时间的 TimeSpan 对象。When this method returns, contains a TimeSpan object that is set to the amount of time that an item in the session data store has been locked.

lockId
Object

当此方法返回时,请包含一个设置为当前请求的锁定标识符的对象。When this method returns, contains an object that is set to the lock identifier for the current request. 有关锁定标识符的详细信息,请参见 SessionStateStoreProviderBase 类摘要中的“锁定会话存储区数据”。For details on the lock identifier, see "Locking Session-Store Data" in the SessionStateStoreProviderBase class summary.

actions
SessionStateActions

当此方法返回时,请包含 SessionStateActions 值之一,指示当前会话是否为未初始化的无 Cookie 会话。When this method returns, contains one of the SessionStateActions values, indicating whether the current session is an uninitialized, cookieless session.

返回

使用会话数据存储区中的会话值和信息填充的 SessionStateStoreDataA SessionStateStoreData populated with session values and information from the session data store.

示例

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

注解

GetItemExclusive AcquireRequestState当属性设置为true(默认值)时SessionStateModule EnableSessionState ,对象在请求开始时调用方法。The SessionStateModule object calls the GetItemExclusive method at the beginning of a request, during the AcquireRequestState event, when the EnableSessionState attribute is set to true, which is the default. 如果特性设置为, ReadOnly SessionStateModule则对象改为调用方法。GetItem EnableSessionStateIf the EnableSessionState attribute is set to ReadOnly, the SessionStateModule object instead calls the GetItem method.

方法返回一个SessionStateStoreData对象,该对象使用数据存储区中的会话信息进行填充,更新存储数据的到期日期,并在请求期间锁定数据存储区中的会话项数据。 GetItemExclusiveThe GetItemExclusive method returns a SessionStateStoreData object populated with session information from the data store, updates the expiration date of the stored data, and locks the session-item data at the data store for the duration of the request. 如果在数据存储区中找不到任何会话项数据, GetItemExclusive则该方法lockedoutfalse参数设置null为并返回。If no session-item data is found at the data store, the GetItemExclusive method sets the locked out parameter to false and returns null. 这会导致SessionStateModule对象CreateNewStoreData调用方法,以在数据存储区中创建新的会话项。This causes the SessionStateModule object to call the CreateNewStoreData method to create a new session item in the data store. 如果在数据存储区中找到会话项数据,但数据被锁定,则该GetItemExclusive方法out locked out将参数设置为true,并将lockAge参数设置为当前日期和时间减去日期当项被锁定(从数据存储中检索)和时间时,将lockId out参数设置为从数据存储中检索到的锁标识符,并返回nullIf session-item data is found at the data store but the data is locked, the GetItemExclusive method sets the locked out parameter to true, sets the lockAge out parameter to the current date and time minus the date and time when the item was locked (which is retrieved from the data store), sets the lockId out parameter to the lock identifier retrieved from the data store, and returns null. 这会导致SessionStateModule对象在半秒GetItemExclusive间隔后再次调用方法,以尝试检索会话项信息并获取数据锁。This causes the SessionStateModule object to call the GetItemExclusive method again after a half-second interval to attempt to retrieve the session-item information and obtain a lock on the data. 如果将out参数设置为lockAge的值超出ExecutionTimeout该值, SessionStateModule则会调用ReleaseItemExclusive方法GetItemExclusive清除对会话项数据的锁定,然后再次调用方法。If the value that the lockAge out parameter is set to exceeds the ExecutionTimeout value, then the SessionStateModule calls the ReleaseItemExclusive method to clear the lock on the session-item data, and then calls the GetItemExclusive method again.

actionFlagscookielesstrue特性都设置为时,将使用参数。 regenerateExpiredSessionIdThe actionFlags parameter is used when the cookieless and regenerateExpiredSessionId attributes are both set to true. 值设置为InitializeItem指示会话数据存储区中的条目是需要初始化的新会话。 actionFlagsAn actionFlags value set to InitializeItem indicates that the entry in the session data store is a new session that requires initialization. 会话数据存储中未初始化的条目是通过调用CreateUninitializedItem方法创建的。Uninitialized entries in the session data store are created by a call to the CreateUninitializedItem method. 如果会话数据存储区中的项不是未初始化的项, actionFlags则该参数将设置为零。If the item from the session data store is not an uninitialized item, the actionFlags parameter will be set to zero.

支持无 cookie 会话的自定义会话状态存储实现程序应actionFlagsout参数设置为从当前项的会话数据存储区中返回的值。Custom session-state store implementers that support cookieless sessions should set the actionFlags out parameter to the value returned from the session data store for the current item. 如果请求actionFlags的会话存储项的参数值InitializeItem等于枚举值,则在设置actionFlags out参数后GetItemExclusive ,该方法应将数据存储中的值设置为零。If the actionFlags parameter value for the requested session-store item equals the InitializeItem enumeration value, then the GetItemExclusive method should set the value in the data store to zero after setting the actionFlags out parameter.

适用于

另请参阅