Replacing or improving Session vars usage - advice

Discussion in 'ASP General' started by Larry Neylon, Feb 22, 2006.

  1. Larry Neylon

    Larry Neylon Guest


    I'm working on a VBScript application on IIS6 and I'm looking for some
    advice about the best way of replacing or improving session variable usage.

    The application is in a secure extranet environment. Currently the
    application has a search customers page with 10 search fields which list the
    results below the search fields. The requirement for this screen was that
    the user could return to this result page at any point from any page in the
    application and see his last set of results.

    As a quick fix I used session variables to store the search values and
    loaded them into the search page upon return. Works fine and didn't worry
    me too much about using 10 session vars.

    Now the users want similar functionality on all search screens (another 6)
    giving me a potential of 60 session variables for search results (on top of
    about another 10 legacy session vars).

    Suddenly I am worried about 70 session variables, potentially containing
    reasonably long strings, with a 2 hour session timeout for a potential 1000

    What would people recommend I do to either replace the session variables or
    improve performance of them.

    My thoughts are:

    1. Store in the database alongside the user record. I'm already retrieving
    the user record on most pages so it would be a case of getting the extra 60
    fields from the DB when required. Would also provide cross session result

    2. Cookies. Have only ever used sparingly. Would this be too much data
    for storing in cookies ? Any performance trade-off ?

    3. Store an array/arrays in fewer session variables. Each search result
    page could just have one session variable with an array of all the search
    field values for that page. Would one session variable containing an array
    be much better than 10 session variables ?

    4. Just use the 70 session variables and stick more memory in the server if
    we get issues. Probably the cheapest and easiest solution, though not the
    right one I'm sure.

    Any advice would be much appreciated as I'm kind of at the limit of what I
    know about performance issues.

    Many thanks,
    Larry Neylon, Feb 22, 2006
    1. Advertisements

  2. Store the values in the database.
    Rather than inventing a field for each value use XML.

    Create a User Config table with the fields (I'm using SQL Server parlance)

    UserID int, Key varchar(512), XML ntext

    When a page receives the search request it can create an XML DOM and store
    the values in the XML:-

    Dim oDOM

    Set oDOM = Server.CreateObject("msxml2.DOMDocument.3.0")

    oDOM.loadXML "<config />"

    AddElem oDOM, "myField", Request.Form("myField")


    Function AddElem(parent, name, value)

    Set AddElem = parent.createElement(name)

    If Not IsNull(value) Then
    AddElem.Text = CStr(value)
    End If

    End Function

    The user choices can then be saved from oDOM.xml property in the UserConfig
    table. I use the the page URL as a key e.g.,

    When the user revisits the page you use the UserID and the page URL to fetch
    an XML string that you can then load an XML DOM with. You can subsequently
    retrieve the values for the fields from the XML.

    This approach is memory efficient and survives cross sessions (potentially
    allowing you to drop the session timeout).

    Anthony Jones, Feb 23, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin SB

    Re: Session vars

    Justin SB, Jun 25, 2003, in forum: ASP .Net
    Justin SB
    Jun 25, 2003
  2. Jon

    app vars and cache vars

    Jon, Dec 14, 2004, in forum: ASP .Net
  3. Linuxguy123
    Paddy O'Loughlin
    Feb 20, 2009
  4. caccolangrifata
    Chris Torek
    Jul 22, 2011
  5. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Chris Hohmann
    Apr 11, 2005

Share This Page