IIS, Session State and Virtual Directories

asp.netiissession-state

I've created a web site with ASP.NET 2.0 and I'm using a session variable to determine if a user has filled out an age verification form. Everything works as expected (I can read the session variable on all pages) until a user goes to a virtual directory. When they do so, the page can't read the session variable.

After much research, I've so far done the following.

  1. Turn on the ASP.NET State Service

  2. Added a sessionState node to my web.config files, changing the mode to StateServer (for the web site and virtual directory).

    <sessionState
    mode="StateServer"
    cookieless="false"
    timeout="20"
    stateConnectionString="tcpip=127.0.0.1:42424"
    />

  3. Generated a new machineKey and added it to both the site and the virtual directory…

    <machineKey
    validationKey="…128…"
    decryptionKey="…64…"
    validation="SHA1"
    decryption="AES"
    />

  4. Created a new application pool and made sure both the web site and it's virtual directory are using the same application pool.

If I write out the session id <%= Session.SessionId %> it is the same on pages in and out of the virtual directory (it's the same throughout the site). I just can't get that session variable! Does anyone know what else I can try to get this to work??

Thanks.

Best Answer

Different virtual directory = different application and applications don't share session data between them. Perhaps a redesign of your applications to avoid this?

Here is a possible solution to sharing session data between ASP.NET applications.

Passing session data between ASP.NET Applications