Click to See Complete Forum and Search --> : Infinte loop in session_start


amirt
March 3rd, 2009, 07:55 AM
Hello all,

I have a problem of infinite loop in my asp.net application in session_start.
it's located in global.asax and the code goes like this:

Try
Dim MyClassVars As MyClassVarsClass = New MyClassVarsClass
If Not HttpContext.Current.Request.Cookies("MaxmindVar") Is Nothing AndAlso HttpContext.Current.Request.Cookies("MaxmindVar").Value <> "" Then
sessionVisitor.InitializeSession(Request, Request.ServerVariables, Session, True, True, HttpContext.Current.Request.Cookies("MaxmindVar").Value)
Else
sessionVisitor.InitializeSession(Request, Request.ServerVariables, Session, True, True, PayoutsVars.MaxMindString)
End If
Catch ex As Exception
Log("MyClass", "SessionVisitor Problem. " & ex.ToString, False)
End Try

MyClassVars.SessionId = "pyhyt" & Session.SessionID
Dim requestedURL As String = Request.Url.ToString
If requestedURL.IndexOf("tid=") = -1 Then
' check if the url has something in the querystring, and handle accordingly
Dim token As String = MyHashing.cmpHashHandler.CreateToken(Session.SessionID)
MyClassVars.Token = token
MyClassVars.MaxMindString = "US"
MyHashing.cmpHashHandler.AddNewRecordToSortedList (token, MyClassVars)
If requestedURL.IndexOf("?") > -1 Then
requestedURL = requestedURL & "&tid=" & token
Else
requestedURL = requestedURL & "?tid=" & token
End If
End If
Response.Redirect(requestedURL)
Response.AppendToLog("SessionStart")
End If


when i run my app. it gets into this loop in this function.
I have the same code exactly in my laptop and no problem there so I guess the different machine may cause the problem, maybe I'm missing something? the iis configuratrion is also the same...
help? :blush:

dglienna
March 3rd, 2009, 11:02 PM
You need to show more code...

amirt
March 4th, 2009, 01:43 AM
this is the code...
remarking it solves the problem (but I need this code...)

DataMiser
March 5th, 2009, 01:12 AM
Just a guess but is it possible that the initializesession is causing the session start to fire again?

amirt
March 5th, 2009, 01:39 AM
nope.
I correct myself -
only this code shoyld be remarked to solve the problem:

MyClassVars.SessionId = "pyhyt" & Session.SessionID
Dim requestedURL As String = Request.Url.ToString
If requestedURL.IndexOf("tid=") = -1 Then
' check if the url has something in the querystring, and handle accordingly
Dim token As String = MyHashing.cmpHashHandler.CreateToken(Session.SessionID)
MyClassVars.Token = token
MyClassVars.MaxMindString = "US"
MyHashing.cmpHashHandler.AddNewRecordToSortedList (token, MyClassVars)
If requestedURL.IndexOf("?") > -1 Then
requestedURL = requestedURL & "&tid=" & token
Else
requestedURL = requestedURL & "?tid=" & token
End If
End If
Response.Redirect(requestedURL)
Response.AppendToLog("SessionStart")
End If

my guess it's something with the response.redirect...
any ideas anyone??

GremlinSA
March 5th, 2009, 12:05 PM
nope.
I correct myself -
only this code shoyld be remarked to solve the problem:

my guess it's something with the response.redirect...
any ideas anyone??

Have you tried the code like this ...

MyClassVars.SessionId = "pyhyt" & Session.SessionID
Dim requestedURL As String = Request.Url.ToString
If requestedURL.IndexOf("tid=") = -1 Then
' check if the url has something in the querystring, and handle accordingly
Dim token As String = MyHashing.cmpHashHandler.CreateToken(Session.SessionID)
MyClassVars.Token = token
MyClassVars.MaxMindString = "US"
MyHashing.cmpHashHandler.AddNewRecordToSortedList (token, MyClassVars)
If requestedURL.IndexOf("?") > -1 Then
requestedURL = requestedURL & "&tid=" & token
Else
requestedURL = requestedURL & "?tid=" & token
End If
Response.Redirect(requestedURL)
End If
Response.AppendToLog("SessionStart")
End If

you should only need to redirect if you alter the url ....

Gremmy..