SessionStateStoreProviderBase.CreateUninitializedItem(HttpContext, String, Int32) 方法

定义

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

public:
 abstract void CreateUninitializedItem(System::Web::HttpContext ^ context, System::String ^ id, int timeout);
public abstract void CreateUninitializedItem (System.Web.HttpContext context, string id, int timeout);
abstract member CreateUninitializedItem : System.Web.HttpContext * string * int -> unit
Public MustOverride Sub CreateUninitializedItem (context As HttpContext, id As String, timeout As Integer)

参数

context
HttpContext

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

id
String

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

timeout
Int32

当前请求的会话 TimeoutThe session Timeout for the current request.

示例

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

注解

CreateUninitializedItemcookieless 和属性均为时,方法与会话一起使用 regenerateExpiredSessionId trueThe CreateUninitializedItem method is used with sessions when the cookieless and regenerateExpiredSessionId attributes are both true. regenerateExpiredSessionId attribute如果设置为,则在 true SessionStateModule SessionID 遇到过期值时使对象生成新值 SessionIDHaving the regenerateExpiredSessionId attribute set to true causes the SessionStateModule object to generate a new SessionID value when an expired SessionID value is encountered.

生成新值的过程 SessionID 需要将浏览器重定向到包含新生成的值的 URL SessionIDThe process of generating a new SessionID value requires redirecting the browser to a URL that contains the newly generated SessionID value. CreateUninitializedItem方法在包含过期值的初始请求期间调用 SessionIDThe CreateUninitializedItem method is called during the initial request that contains an expired SessionID value. SessionStateModule 对象获取 SessionID 用于替换过期值的新值后,它会调用 CreateUninitializedItem 方法,将未初始化的项添加到会话状态数据存储区。After the SessionStateModule object acquires a new SessionID value to replace the expired value, it calls the CreateUninitializedItem method to add an uninitialized entry to the session-state data store. 然后,浏览器将重定向到包含新生成的 SessionID 值的 URL。The browser is then redirected to the URL containing the newly generated SessionID value. 会话数据存储中的未初始化条目的存在确保了包含新生成的值的重定向请求 SessionID 不会被误认为已过期会话的请求,而是被视为新会话。The existence of the uninitialized entry in the session data store ensures that the redirected request that includes the newly generated SessionID value is not mistaken for a request for an expired session and is, instead, treated as a new session.

会话数据存储区中未初始化的条目与新生成的值相关联, SessionID 并且仅包含默认值,包括到期日期和时间以及与和方法的参数相对应的值 actionFlags GetItem GetItemExclusiveThe uninitialized entry in the session data store is associated with the newly generated SessionID value and contains only default values, including an expiration date and time and a value that corresponds to the actionFlags parameter of the GetItem and GetItemExclusive methods. 会话状态存储中的未初始化条目应包含 actionFlags 等于 InitializeItem 枚举值的值。The uninitialized entry in the session-state store should include an actionFlags value equal to the InitializeItem enumeration value. 此值 SessionStateModule 通过和方法传递给对象 GetItem GetItemExclusive ,并通知 SessionStateModule 对象当前会话是新的、未初始化的会话。This value is passed to the SessionStateModule object by the GetItem and GetItemExclusive methods, and informs the SessionStateModule object that the current session is a new but uninitialized session. SessionStateModule然后,对象将初始化新会话并引发 Session_OnStart 事件。The SessionStateModule object will then initialize the new session and raise the Session_OnStart event.

有关无 cookie 会话的详细信息,请参阅 IsCookieless 属性。For more information about cookieless sessions, see the IsCookieless property.

适用于