ISessionIDManager.CreateSessionID(HttpContext) 方法

定义

创建一个唯一的会话标识符。Creates a unique session identifier.

public:
 System::String ^ CreateSessionID(System::Web::HttpContext ^ context);
public string CreateSessionID (System.Web.HttpContext context);
abstract member CreateSessionID : System.Web.HttpContext -> string
Public Function CreateSessionID (context As HttpContext) As String

参数

context
HttpContext

引用用于处理 HTTP 请求(例如,HttpContextRequest 属性)的服务器对象的当前 Response 对象。The current HttpContext object that references server objects used to process HTTP requests (for example, the Request and Response properties).

返回

String

唯一会话标识符。A unique session identifier.

示例

下面的代码示例实现 CreateSessionID 方法。The following code example implements the CreateSessionID method. 方法创建一个新的 Guid ,用作会话标识符。The method creates a new Guid to be used as a session identifier.

public string CreateSessionID(HttpContext context)
{
  return Guid.NewGuid().ToString();
}
Public Function CreateSessionID(context As HttpContext) As String _
  Implements ISessionIDManager.CreateSessionID

  Return Guid.NewGuid().ToString()
End Function

注解

CreateSessionID方法用于生成唯一会话标识符, SessionStateModule 对象将使用该标识符来标识新会话。The CreateSessionID method is used to generate a unique session identifier that the SessionStateModule object will use to identify a new session. 返回的值 CreateSessionID 必须唯一,并且必须包含可存储在 HTTP 响应和请求中的有效字符。The value returned by CreateSessionID must be unique and must contain valid characters that can be stored in an HTTP response and request. 如果实现返回的值可能 CreateSessionID 包含在 HTTP 响应或请求中无效的字符,则应使用 UrlEncode 方法对方法实现中的会话标识符值进行编码 SaveSessionID ,并使用 UrlDecode 方法对方法实现中的会话标识符值进行解码 GetSessionIDIf it is possible that the value returned by your CreateSessionID implementation contains characters that are not valid in an HTTP response or request, you should use the UrlEncode method to encode the session-identifier value in your SaveSessionID method implementation and the UrlDecode method to decode the session-identifier value in your GetSessionID method implementation.

适用于