PRB: Session variables lost when ASP is located in framesetLast reviewed: December 15, 1997Article ID: Q178037 |
The information in this article applies to:
SYMPTOMSValues of session variables defined in an Active Server Pages (ASP) page are empty when you attempt to access the values from other ASP pages within the frameset.
CAUSEThe following conditions cause this error to occur:
Active Server Pages keeps track of sessions through the use of cookies. When using a frameset that contains ASP files, the cookies are not returned to the browser until the entire frameset is loaded. For this reason, if a session has not already been established (that is, a SessionID cookie has not been passed to the browser), Active Server Pages creates a new session for each ASP file within the frameset. NOTE: If the session variable is initialized within the Session_OnStart of the Global.asa and the variable increments (for example, a variable that holds a value indicating how many people have hit your site), the value will increment by an amount equal to the number of frames containing ASP pages you have in your frameset. This behavior is due to the Session_OnStart executing for each ASP file in your frameset.
RESOLUTIONActive Server Pages maintains a session only when necessary (for example, if a session variable is created). To avoid this behavior you must establish a session before the frameset is processed. In most cases, the easiest way to do this is by changing the file which defines the frameset from an HTML file to an ASP file.
MORE INFORMATION
Steps to Reproduce BehaviorCreate the following files: Main.htm:
<HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Developer Studio"> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY> <FRAMESET FRAMEBORDER=0 SCROLLING=YES ROWS="15%, 70%, *"> <FRAME NAME="Top" SCROLLING="NO" SRC="Top.asp"> <FRAME NAME="Middle" SCROLLING="AUTO" SRC="Middle.asp"> <FRAME NAME="Bottom" SCROLLING="NO" SRC="Bottom.asp"> </FRAMESET> </BODY> </HTML>Top.asp:
<%@ LANGUAGE="VBSCRIPT" %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0"> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY> <% Response.Write( "Top.asp: " & Session.SessionID ) %> <%'set a session variable I want to be global to all asp files in the frameset session("GlobalVar")="Top"%> </BODY> </HTML>Middle.asp:
<%@ LANGUAGE="VBSCRIPT" %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0"> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY> <% Response.Write( "Middle.asp: " & Session.SessionID ) %> <SCRIPT LANGUAGE="VBScript"> Sub CommandButton1_Click() 'display the global variable set in top.asp msgbox "<%=session("GlobalVar")%>" 'if GlobalVar is blank, it means the variable is scoped to a 'different session. end sub </SCRIPT> <OBJECT ID="CommandButton1" WIDTH=96 HEIGHT=32 CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57"> <PARAM NAME="Caption" VALUE="display gvar"> <PARAM NAME="Size" VALUE="2540;846"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="3"> </OBJECT> </BODY> </HTML>Bottom.asp:
<%@ LANGUAGE="VBSCRIPT" %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0"> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY> <% Response.Write( "Bottom.asp: " & Session.SessionID ) %> <% Session("MyVar") = "Bottom" %> </BODY> </HTML>Browse Main.htm and you will see that the session IDs are all different. Rename Main.htm to Main.asp and add the following line of code after the </FRAMESET> tag:
<% Session("MyVar") = "Main" %>Now only one session is created and is maintained until the session ends.
Keywords : VIASP Technology : kbInetDev Version : WINNT:1.0,1.0b Platform : winnt Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |