SYMPTOMS
When you browse to a child virtual root that is nested within a parent
virtual root and then navigate to the parent virtual root session,
variables appear to be lost.
The following table summarizes the behavior:
Child 1 app state held Child 2 app state held
Root app called first No No
Root app called before Child 1 only No Yes
Root app called before Child 2 only Yes No
Root app called last Yes Yes
CAUSE
NOTE: There is a registry entry, CheckForNestedVroots(Default = 1), that ASP uses to check for nested virtual roots so that if a new nested virtual root is created while the system is running, the running
application sees the new nested Global.asa file as soon as it is
saved. From this registry parameter you can infer that ASP is
designed to check for Global.asa files in subdirectories.
However, this behavior works in only one case: If all nested
applications start before the root application, ASP checks for
Global.asa files in all linked applications (both above and at the
same level of the calling application). However, if the
root application is called first or called before any nested
application, only the root application's session state (sessionid and
session variables) is maintained; it is not as if ASP does not check for
nested virtual roots.
Internet Service Manager allows users to set up directories and their
subdirectories as virtual roots. This creates a situation where there are
virtual roots with nested virtual roots, which themselves can contain
Global.asa files with
Application_OnStart and
Session_OnStart subroutines.
Here is an example directory structure in which each virtual directory
contains a Global.asa file:
C:\InetPub\wwwroot <Home>
Global.asa
C:\InetPub\wwwroot\Test2 (Nested)
Global.asa
C:\InetPub\wwwroot\Test2\Test3 (Nested)
Global.asa
C:\InetPub\wwwroot\Test4
Global.asa
After the user browses to the root directory, which is the Wwwroot directory in a default installation, the SessionID is created and does
not change even when navigating to other nested virtual roots, but the
Application-scoped variables continue to change each time the users browses
a page in a different virtual root. This causes the Application variables
to appear to be lost.
However, if the root directory is the last directory navigated to and has
never been visited before, then each nested directory maintains its own
SessionID and Application and Session scoped variables.
This behavior is caused by the fact that once the root <home> directory is browsed, IIS continues to send the same SessionCookie back to the browser; however, if nested virtual roots are browsed prior to browsing the home root, SessionCookies are sent for each nested virtual root, thereby generating multiple SessionIDs for each nested virtual root. The first time the home root is browsed the SessionCookie is fixed thereafter.