When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Friday, April 28, 2000

Managing Session State using aSMS, Part 4

By Sessionmgmt@hotmail.com

  • Read Part 1

  • Using aSMS
    In IIS Session Starts automatically when the users hit the first web page, usually default.asp. In aSMS developers have the flexibility of starting the session in any page from where they want to use session variables.

    - continued -

    aSMS does not use IISs Session management. It uses its internal session management tool. Developers can disable the IIS Session State from MMC there by conserving lot of resources.

    How to Start a Session
    To start a Session, a developer must first create an instance of the aSMS Session object. This is done by calling the Server.CreateObject() method, and passing it Session.Management as the ProgId:

    <% Set objSession = Server.CreateObject("Session.Management") %>

    Once created, session can be started using the SessionStart() method

    <% objSession.SessionStart() %>

    How to End a Session
    To end a session SessionEnd() method can be used.

    <% objSession.SessionEnd() %>

    How to Check Session
    aSMS allows the developers to check for the session in any page by just calling CheckSession() method. This method checks whether the user is still in session or timed out.

    <% objSession.CheckSession() %>

    As a general rule of thumb this method has to be called in all the pages where session variables are used. This gives more flexibility to the developers and also resources can be conserved in other pages where session variables are not used.

    How to Assign Session Variables
    Session variables can be assigned by using SetSession() method. SetSession() method requires two arguments, one is name of the session variable and other is the value.

    <% objSession.SetSession cstr(strName), cstr(strValue) %>

    In aSMS standard edition, developers can use the predefined variable names in LDAP. LDAP contains more than 150 variable names defined with data types as int, float, date, image, array etc. Developers can select the appropriate variable names and use them.

    For e.g. some of the commonly used Session variable names and their corresponding LDAP variable names with their type

      FirstName givenName (string)
      LastName sn (string)
      EmailAddress mail (string)
      Password userPassword (string)
      State accountStatus (int)

    For the complete listing of LDAP variable names Click Here.

    Session variables can be assigned as:

      Set objSession = Server.CreateObject("Session.Management") 
      objSession.SetSession "givenname", "John"
      objSession.SetSession "sn", "Anderson"
      objSession.SetSession "mail", "John@Anderson.com" 
      objSession.SetSession "userPassword", "password"
      objSession.SetSession "accountStatus", "1"
      Set objSession = nothing 

    How to retrieve the Session Variables
    Session variables can be retrieved by using GetSession() method. GetSession() requires the session variable name passed as argument.

    <% objSession.GetSession(cstr(strName)) %>
      Dim strFirstName, strLastName, strEmailAddress
      Dim strPassword, intStatus
      Set objSession = Server.CreateObject("Session.Management") 
      strFirstName = objSession.GetSession ("givenname") 
      strLastName = objSession.GetSession ("sn") 
      strEmaiAddress = objSession.GetSession ("mail") 
      strPassword = objSession.GetSession ("userPassword") 
      intStatus = objSession.GetSession ("accountStatus ") 
      Set objSession = nothing 

    By this approach the session variables can be easily shared across different webservers in the Web farm without losing the data. As mentioned earlier LDAP is optimized for fast single read and write operations, so storing the session variables in LDAP wont harm the performance of the web server.

    Migrating a current web site to use aSMS
    For Migrating a current web site to aSMS check Migration/Deployment Page.

    In this paper, we've discussed state management in a Web farm where two or more servers are used to host a single site. We've looked at several possible approaches to managing session state, including building stateless applications, storing session state on the client, using session-aware load-balancing, and storing session state on a central computer using asp Session Management Server..

    Happy Programming!


  • Visit the aSMS HomePage
  • Download aSMS (free!)

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article