This documentation is archived and is not being maintained.

ISessionIDManager.GetSessionID Method

Gets the session identifier from the context of the current HTTP request.

Namespace:  System.Web.SessionState
Assembly:  System.Web (in System.Web.dll)

string GetSessionID(
	HttpContext context


Type: System.Web.HttpContext
The current HttpContext object that references server objects used to process HTTP requests (for example, the Request and Response properties).

Return Value

Type: System.String
The current session identifier sent with the HTTP request.

The GetSessionID method is called by the SessionStateModule during the HttpApplication.AcquireRequestState and HttpApplication.EndRequest events. If you cannot retrieve a valid session identifier from the HTTP request, return null. If the SessionStateModule receives null from the GetSessionID method, it will call the CreateSessionID method to get a new session identifier for a new session.

If 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.

The following code example shows a partially implemented GetSessionID method. If your custom session-ID manager supports cookieless session identifiers, you will need to implement a solution for sending and retrieving session identifiers in the URL, such as an ISAPI filter.

public string GetSessionID(HttpContext context)
  string id = null;

  if (pConfig.Cookieless == HttpCookieMode.UseUri)
    // Retrieve the SessionID from the URI.
    id = context.Request.Cookies[pConfig.CookieName].Value;

  // Verify that the retrieved SessionID is valid. If not, return null.

  if (!Validate(id))
    id = null;

  return id;

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.