HttpContext.SetSessionStateBehavior(SessionStateBehavior) 方法

定义

设置支持 HTTP 请求所需的会话状态行为的类型。Sets the type of session state behavior that is required in order to support an HTTP request.

public:
 void SetSessionStateBehavior(System::Web::SessionState::SessionStateBehavior sessionStateBehavior);
public void SetSessionStateBehavior (System.Web.SessionState.SessionStateBehavior sessionStateBehavior);
member this.SetSessionStateBehavior : System.Web.SessionState.SessionStateBehavior -> unit

参数

sessionStateBehavior
SessionStateBehavior

枚举值之一,该值指定需要什么类型的会话状态行为。One of the enumeration values that specifies what type of session state behavior is required.

异常

该方法是在引发 AcquireRequestState 事件之后调用的。The method was called after the AcquireRequestState event was raised.

注解

在 ASP.NET 默认实现中,HTTP 请求处理程序通过实现 IRequiresSessionState 接口或 IReadOnlySessionState 接口来指示它是否需要会话状态。In the ASP.NET default implementation, an HTTP request handler indicates whether it requires session state by implementing the IRequiresSessionState interface or the IReadOnlySessionState interface. 使用 SetSessionStateBehavior 方法和 SessionStateBehavior 枚举,你可以提供有关处理请求所需的会话状态支持类型的更多详细信息。The SetSessionStateBehavior method and the SessionStateBehavior enumeration let you provide more detail about what type of session state support is required in order to handle a request. 有关详细信息,请参见 SessionStateBehavior 枚举。For more information, see the SessionStateBehavior enumeration.

必须先调用 SetSessionStateBehavior 方法,然后才能 AcquireRequestState 管道事件。The SetSessionStateBehavior method must be called before the AcquireRequestState pipeline event. 此事件期间或之后发生的调用将导致 InvalidOperationException 异常。Calls that occur during or after this event will cause an InvalidOperationException exception.

适用于

另请参阅