PRB: Session_OnStart Event Enters Infinite Loop (284466)



The information in this article applies to:

  • Microsoft Active Server Pages

This article was previously published under Q284466

SYMPTOMS

When you use the Response.Redirect method in the Session_OnStart event, the event enters an infinite loop.

CAUSE

When a user browses the first .asp page in a Web site, the Global.asa file in that virtual directory fires the Session_OnStart event. If the user is redirected to another page in the same application, Global.asa fires the Session_OnStart event again. This behavior continues until a session is initialized. As a result, if the user is redirected before the session is initialized, the server continually fires a new session.

RESOLUTION

To resolve this problem, provide code that initializes the session prior to redirection. For example:
<SCRIPT RUNAT=Server LANGUAGE=VBScript>
Sub Session_OnStart
    'Add code here to initialize the session
    Session("init") = True
    Response.Redirect("somepage.asp")
End Sub
</SCRIPT>
				

MORE INFORMATION

Steps to Reproduce Behavior

  1. Add three pages, named Page1.asp, Page2.asp, and Global.asa, to an Internet Information Server (IIS) application.
  2. Paste the following code in the Global.asa file:
    <SCRIPT RUNAT=Server LANGUAGE=VBScript>
    Sub Session_OnStart
        Response.Redirect("Page2.asp")
    End Sub
    </SCRIPT>
    					
  3. In your Internet browser, browse to Page1.asp. The browser is caught in a loop between Page1.asp and Page2.asp.

Modification Type:MajorLast Reviewed:5/8/2001
Keywords:kbASPObj kbDSupport kbprb kbScript kbWebServer KB284466