Forum Moderators: open

Message Too Old, No Replies

Track time of a session

track how long a specific session lasts

         

macrost

5:00 pm on Feb 27, 2003 (gmt 0)

10+ Year Member



To all. I have a problem that I can't wrap my brain around. I am initializing a session at the start of a script if it's not there. I need to find out how long that session lasts before I receive and error.

Dim xsl, template, processor, strXML, sessionid, xml, starttime1, endtime
sessionid = Request.QueryString("jsessionid")

If Application("sessionid") = "" Then
Application("sessionid") = sessionid
starttime1 = Timer()
End If
... lots of code taken out ...
... bottom of script ...

'start email errors
Dim ObjMail, intMailFormat, strSubject
endtime = Timer()
intMailFormat = 1
strSubject = "paging error"
If Not xml Is Nothing Then
If Not xml.documentElement Is Nothing Then
'EXCEPTION IS WHAT WE ARE LOOKING FOR
If xml.documentElement.nodeName = "Exception" Then
Set ObjMail = Server.CreateObject("CDONTS.NewMail")
ObjMail.FROM = "service@favoriteplaces.net"
ObjMail.TO = "mrost@travelnow.com"
ObjMail.Subject = strSubject
ObjMail.BodyFormat = intMailFormat
ObjMail.Body = "This error was generated at request time." & vbcrlf & Request.ServerVariables("HTTP_REFERER") & vbcrlf & Date & vbcrlf & Time & vbcrlf & "Session lasted: " & endtime - starttime1 & vbcrlf & "XML Query:" & vbcrlf & strXML & vbcrlf & vbcrlf & vbcrlf & "XML Response:" & vbcrlf & xmlhttp.responseText
ObjMail.Send
Set ObjMail = Nothing
End If
End If
End If
Set xsl = Nothing
Set xml = Nothing
Set xmlhttp = Nothing
Set template = Nothing
%>


I'm about to pull out all of my hair on this one. Any help would be appreciated!
Mac

aspdaddy

5:08 pm on Feb 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I'm not sure if this is what you are trying to do , but the basic logic is to grab the current time on session start, then access the length of a session at any time by using datediff with the current time.

This code is not checked, ;

sub session_onStart()
session("start")= Now()
end sub

session_seconds = DateDiff("s", Now(),Session("start"))

macrost

5:24 pm on Feb 27, 2003 (gmt 0)

10+ Year Member



aspdaddy,
Ok, thanks for the pointer. Unfortunatley I have to wait 30 minutes as that is how long the other web site's jsessionid are supposed to last.
Thanks!
Mac

aspdaddy

5:26 pm on Feb 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



call session.abandon

macrost

7:11 pm on Feb 27, 2003 (gmt 0)

10+ Year Member



aspdaddy,
Hmmm, when I do get an email of an exception, the only thing that is in the body of the email now is simply 0. Any ideas?

RossWal

12:52 am on Feb 28, 2003 (gmt 0)

10+ Year Member



Wait a minute (or wait 30 minutes as the case may be ;-) ).
It sounds like you are capturing the time (now()) in a session variable, then waiting for the session to expire, then going back to your session variable to compute elapsed time. If that's the case, the original session variable has expired along with the session and you lost your timer. You may need need a more persistent data store like an application variable, text file, or database.

HTH,
Ross

aspdaddy

10:07 am on Feb 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where are you calling the code?

If it is called on session_onend, i think:) it will be ok becaiuse the event happens just before the session ends.

If it is called by a page, then it should also be ok because every page request has a session created in session onstart.

Is Session_onend reliable? I'm not sure when it is/isnt, maybe someone else can help out here!

macrost

8:04 pm on Feb 28, 2003 (gmt 0)

10+ Year Member



Ok, we are getting somewhere. I am going to post the full code below.

<% Response.Buffer=True %>
<%

Dim startTime : startTime = Timer()
Dim xsl, template, processor, strXML, sessionid, xml, starttime1, endtime
sessionid = Request.QueryString("jsessionid")
sub session_onStart()
session("start")= Now()
end sub
If Application("sessionid") = "" Then
Application("sessionid") = sessionid
starttime1 = Timer()
End If
'response.write("<!--" & sessionid &"-->")
'If usersession <> 1 Then
'Response.Redirect("error.html")
'End If
Dim carry : carry = Request.QueryString("resType")
If carry = "" Then
Response.Redirect("error.html")
End If

Server.ScriptTimeout = 500
Response.Write("<script language=javascript src=splash_begin.js></script>")
Response.Write("<div id=splashScreen style=position:absolute;z-index:5;top:30%;left:35%;>")
Response.Write("<TABLE align=center BGCOLOR=#000000 BORDER=0 BORDERCOLOR=#000000 CELLPADDING=0 CELLSPACING=0 HEIGHT=200 WIDTH=300>")
Response.Write("<TR>")
Response.Write("<TD WIDTH=100% HEIGHT=100% BGCOLOR=#FFFFFF ALIGN=center VALIGN=MIDDLE>")
Response.Write("<BR/><BR/>")
Response.Write("<FONT FACE=Helvetica,Verdana,Arial SIZE=3 COLOR=#639ACE><B>FavoritePlaces.net is now searching multiple suppliers for the best rates. Please wait...</B></FONT>")
Response.Write("<BR/>")
Response.Write("<IMG SRC=../images/wait.gif BORDER=1 WIDTH=75 HEIGHT=15/><BR/><BR/>")
Response.Write("</TD>")
Response.Write("</TR>")
Response.Write("</TABLE>")
Response.Write("</div>")
Response.Flush
Set xml = Server.CreateObject("microsoft.XMLDOM")

strXML = "http://www.travelnow.com/external/xmlinterface.jsp;jsessionid=" & sessionid &"?cid=56035&resType=" & Request.QueryString("resType") & "&xmlVersion=3&xml=<HotelSessionRequest method='runHotelAvailabilityListQuery'></HotelSessionRequest>"

' Get Code

dim xmlhttp
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",strXML,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send

response.write("<!--")
response.write(strXML)
response.write("-->")
response.write("<!--")
response.write(xmlhttp.responseText)
response.write("-->")
Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xml.async = false
xml.loadXml(xmlhttp.responseText)

Set xsl = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xsl.async = false
xsl.load (Server.MapPath("../xsl/russ.xsl"))

Set template = Server.CreateObject("MSXML2.XSLTemplate")
template.stylesheet = xsl
set processor = template.createProcessor()

processor.input = xml
If usersession <> "" Then
processor.addParameter "usersession", usersession
End If
country = Request.QueryString("country")
If country <> "" Then
processor.addParameter "country", country
End If
arrivalDate = Request.QueryString("arrivalDate")
if arrivalDate <> "" then
processor.addParameter "arrivalDate", arrivalDate
end if
departureDate = Request.QueryString("departureDate")
if departureDate <> "" then
processor.addParameter "departureDate", departureDate
end if
resType = Request.QueryString("resType")
If resType <> "" Then
processor.addParameter "resType", resType
End If
rating = Request.QueryString("rating")
If rating <> "" Then
processor.addParameter "rating", rating
End If
city = Request.QueryString("citysearch")
If city <> "" Then
processor.addParameter "citysearch", city
End If
state = Request.QueryString("statesearch")
If state <> "" Then
processor.addParameter "statesearch", state
End If
processor.transform()

response.flush
response.write("<script language=javascript src=splash_end.js></script>")
Response.Write (processor.output)
Response.Write("<!--")
Response.Write("page generated in:")
Response.Write(Timer() - StartTime)
Response.Write("secs.")
Response.Write("-->")
'start email errors
Dim ObjMail, intMailFormat, strSubject, session_seconds
endtime = Timer()
intMailFormat = 1
strSubject = "paging error"
If Not xml Is Nothing Then
If Not xml.documentElement Is Nothing Then
'EXCEPTION IS WHAT WE ARE LOOKING FOR
If xml.documentElement.nodeName = "Exception" Then
session_seconds = DateDiff("H",Session("start"), Now())
Set ObjMail = Server.CreateObject("CDONTS.NewMail")
ObjMail.FROM = "service@favoriteplaces.net"
ObjMail.TO = "mrost@travelnow.com"
ObjMail.Subject = strSubject
ObjMail.BodyFormat = intMailFormat
ObjMail.Body = "This error was generated at request time." & vbcrlf & Request.ServerVariables("HTTP_REFERER") & vbcrlf & Date & vbcrlf & Time & vbcrlf & "Session lasted: " & session_seconds & vbcrlf & "XML Query:" & vbcrlf & strXML & vbcrlf & vbcrlf & vbcrlf & "XML Response:" & vbcrlf & xmlhttp.responseText
ObjMail.Send
Set ObjMail = Nothing
Call session.abandon
End If
End If
End If
Set xsl = Nothing
Set xml = Nothing
Set xmlhttp = Nothing
Set template = Nothing
response.write("<!--" & session_seconds & "-->")
%>


Now, when I do receive a notification, I am changing the diff into minutes by specifying "N". Sorry that this piece of work? (well anyways...) is not documented.

macrost

8:06 pm on Feb 28, 2003 (gmt 0)

10+ Year Member



Oops! Was just looking at DateDiff and I'm specifying "H".

macrost

8:10 pm on Feb 28, 2003 (gmt 0)

10+ Year Member



Guys, sorry for the multiple postings. ;-) Well here is the email that I receive when I encounter the error.
This was today.

This error was generated at request time.
http://www.favoriteplaces.net/hotavail.asp
2/28/2003
1:32:15 PM
Session lasted: 904333
XML Query:
http://www.travelnow.com/external/xmlinterface.jsp;jsessionid=iaac74KvrFSd
Gm?cid=56035&resType=hotel&xmlVersion=3&xml=<HotelSessionRequest
method='runHotelAvailabilityListQuery'></HotelSessionRequest>

XML Response:

<Exception>
<VERSION>3</VERSION>
<SUPPLIER>0</SUPPLIER>
<LOB>3</LOB>
<SOURCE_TECHNOLOGY>2</SOURCE_TECHNOLOGY>
<FUNCTION>2</FUNCTION>
<CATEGORY>5</CATEGORY>
<HANDLING>2</HANDLING>
<SEVERITY>0</SEVERITY>
<ITINERARYID>-1</ITINERARYID>
<AFFILIATEID>56035</AFFILIATEID>
<EXCEPTION_CONDITIONID>658</EXCEPTION_CONDITIONID>
<DATABASE_MESSAGE>XML AvailList Unable To Process
Request</DATABASE_MESSAGE>
<PRESENTATION_MESSAGE>Query could not be created or located in
session</PRESENTATION_MESSAGE>
<VERBOSE_MESSAGE>Query could not be created or located in
session</VERBOSE_MESSAGE>
</Exception>

RossWal

10:03 pm on Feb 28, 2003 (gmt 0)

10+ Year Member



Hey Macrost -
Just noticed it's about hotel availability. As it happens, I'm looking for a nice hotel in San Francisco for tomorrow night. You don't have an pull to keep me from going to the compettition, do ya?

Kidding about the pull, of course .... but not about the competition .....hotwire here I come ;)

macrost

10:07 pm on Feb 28, 2003 (gmt 0)

10+ Year Member



rosswal,
There ya go! :-D
Mac