SessionIDManager..::.CreateSessionID Method Home
This page is specific to:.NET Framework Version:2.03.03.54.0
.NET Framework Class Library
SessionIDManager..::.CreateSessionID Method

Creates a unique session identifier for the session.

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

'Usage

Dim instance As SessionIDManager
Dim context As HttpContext
Dim returnValue As String

returnValue = instance.CreateSessionID(context)

'Declaration

Public Overridable Function CreateSessionID ( _
    context As HttpContext _
) As String

Parameters

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
A unique session identifier.

Implements

ISessionIDManager..::.CreateSessionID(HttpContext)
Remarks

This method is not intended to be called from application code.

The CreateSessionID method returns a unique session identifier that is a randomly generated number encoded into a 24-character string consisting of lowercase characters from a to z and numbers from 0 to 5.

Notes to Inheritors:

You can supply a custom session identifier to be used by ASP.NET session state by creating a class that inherits the SessionIDManager class and overriding the CreateSessionID and Validate methods with your own custom implementations. If your custom session ID does not meet the character constraints enforced by the default implementation of the Validate method, you should override the Validate method to provide validation of your custom session identifier. In this case, the SessionIDManager class will ensure that your custom session identifier is URL encoded in the HTTP response and URL decoded from the HTTP request using the Encode and Decode methods, respectively.

Examples

The following code example shows a class that inherits the SessionIDManager class and overrides the CreateSessionID and Validate methods with methods that supply and validate a Guid as the SessionID.

Imports System
Imports System.Configuration
Imports System.Web.Configuration
Imports System.Web
Imports System.Web.SessionState


Namespace Samples.AspNet.Session

  Public Class GuidSessionIDManager
    Inherits SessionIDManager

    Public Overrides Function CreateSessionID(context As HttpContext) As String
      Return Guid.NewGuid().ToString()
    End Function

    Public Overrides Function Validate(id As String) As Boolean
      Try
        Dim testGuid As Guid = New Guid(id)

        If id = testGuid.ToString() Then _
          Return True
      Catch

      End Try

      Return False
    End Function

  End Class

End Namespace


To use the custom class demonstrated in this example, configure the sessionIDManagerType attribute of the sessionState Element (ASP.NET Settings Schema) element, as shown in the following example.

<sessionState
  Mode="InProc"
  stateConnectionString="tcp=127.0.0.1:42424"
  stateNetworkTimeout="10"
  sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
  sqlCommandTimeout="30"
  customProvider=""
  cookieless="false"
  regenerateExpiredSessionId="false"
  timeout="20"
  sessionIDManagerType="Your.ID.Manager.Type,
    CustomAssemblyNameInBinFolder"
/>
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Other Resources

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View