Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ LANGUAGE="VBScript" %>
- <%Option Explicit%>
- <!--#include file="Include/adovbs.inc"-->
- <%
- '***********************************
- 'Functions
- '***********************************
- 'Function returns a valid Globally Unique ID (GUID) for identifying a session.
- Function GetGuid()
- Dim TypeLib, guid_temp
- Set TypeLib = Server.CreateObject("Scriptlet.TypeLib")
- 'A true GUID contains a unicode null termination, that needs to be stripped to behave like
- ' a string.
- guid_temp = TypeLib.Guid
- GetGuid = Left(guid_temp, Len(guid_temp) - 2)
- Set TypeLib = Nothing
- End Function
- 'This function retrieves the Session information identified by the parameter guidIn. The
- ' resulting Session information is loaded into the Session object, it is not returned.
- Sub GetSessionFromDatabase(guidIn)
- 'Declare Variables
- Dim con, cmd, rs, strSql, guidTemp, i, connectionString
- 'Initialize Variables
- Set con = Server.CreateObject("ADODB.Connection")
- connectionString = Application("Facilities_ConnectionString") & ";WSID=" & Request.ServerVariables("REMOTE_ADDR") & ";"
- '******************
- con.Open connectionString, Application("Facilities_RuntimeUserName"), Application("Facilities_RuntimePassword") 'CONNECTION STRING HERE
- '******************
- Set cmd = Server.CreateObject("ADODB.Command")
- cmd.ActiveConnection = con
- i = 1
- strSql = "SELECT * FROM ASPSessionState WHERE GUID = '" + guidIn + "'"
- Set rs = Server.CreateObject("ADODB.Recordset")
- rs.Open strSql, con
- Session("sync") = "1"
- While Not(rs.EOF)
- ' Response.Write("I am most certainly reading session key " + rs("SessionKey") + " with value " + rs("SessionValue") + " ")
- Session(rs("SessionKey")) = rs("SessionValue")
- rs.MoveNext
- Wend
- ' Response.Write ("My session id is " + Session.SessionID + " ")
- 'Clean up database objects
- rs.Close
- con.Close
- Set rs = Nothing
- Set cmd = Nothing
- Set con = Nothing
- End Sub
- 'This performs cleanup of the Session information identified by the parameter guidIn. All Session
- ' information in the database with the specified GUID is deleted.
- Sub ClearSessionFromDatabase(guidIn)
- 'Declare Variables
- Dim con, cmd, strSql, connectionString, guidTemp
- Dim olParams
- 'Initialize Variables
- Set con = Server.CreateObject("ADODB.Connection")
- connectionString = Application("Facilities_ConnectionString") & ";WSID=" & Request.ServerVariables("REMOTE_ADDR") & ";"
- '******************
- con.Open connectionString, Application("Facilities_RuntimeUserName"), Application("Facilities_RuntimePassword") 'CONNECTION STRING HERE
- '******************
- 'Remove all session variables from the database
- Set cmd = Server.CreateObject("ADODB.Command")
- cmd.ActiveConnection = con
- cmd.CommandText = "DELETE FROM ASPSessionState WHERE GUID = ? OR datediff(day, isnull(saved_time, getdate() - 1), getdate()) >= 1"
- cmd.Parameters.Append cmd.CreateParameter("Guid", adVarChar, adParamInput, 254)
- 'Iterate through all Session variables and add them to the database with the
- ' same GUID as an identifier.
- cmd("Guid") = GetGuid()
- cmd.Execute
- 'Clean up database objects
- con.Close
- Set cmd = Nothing
- Set con = Nothing
- End Sub
- '***********************************
- 'Main code execution
- '***********************************
- Dim guidSave
- If Request.QueryString("guid") & "" <> "" Then
- guidSave = Request.QueryString("guid")
- ' Response.Write("Attempting to retrieve " + guidSave + " ")
- 'Retrieve the session information and redirect to the specified URL
- Call GetSessionFromDatabase(Request.QueryString("guid"))
- 'Clean up the database
- Call ClearSessionFromDatabase(Request.QueryString("guid"))
- response.Write ("Done, set cookie")
- End If
- %>
- <%
- ' DEBUG: output, continue...
- Function Print(n)
- Response.Write("<pre>" & n & "</pre>")
- Response.Flush()
- End Function
- ' DEBUG: output, stop!
- Function Break(n)
- Response.Write("<pre>" & n & "</pre>")
- Response.Flush()
- Response.End()
- End Function
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement