This code stores the URL in the sURL variable by using sURL to set the caption of lblURL1. The setCaption method of the label design-time control places a hyperlink on the page with the SessionID appended to it as a QueryString that the target page will later retrieve.
You call the GetSession function when you need to return session data from the database table. In TestSession 2.asp, the following code demonstrates the execution of GetSession:
dim rs
dim SessionID
SessionID = Request.QueryString("SessionID")
set rs = GetSession(SessionID)
GetSession returns the recordset containing the session data. Then the calling application can extract the session values by using standard the ADO methods:
Response.Write "Customer ID = " & rs("CustomerID") & "<br>"
Response.Write "User Name = " & rs("UserName") & "<br>"
Response.Write "Customer Data = " & rs("CustomerData") & "<br>"
You could argue that returning a recordset is unnecessary because you need to return only one value. However, having the recordset with the data in it for manipulation is handy. ADO and SQL Server are so fast that handling the recordset this way might not add significant overhead. The more string handling you do, the greater the chance that your code will add overhead. You can use a fast XML parser to manage the session data, but then the data will be in XML format, which has its own benefits and challenges.
The function in Database.asp is DeleteSession. DeleteSession takes the SessionID as an incoming parameter and removes the session record from the database. Your application can call DeleteSession any time after you finish with the session record. You might also add a routine on your server that removes old entries in the SessionInfo table. For example, you can add a program to run every day and remove records that are more than 24 hours old.
You can do a lot to improve your application's performance. Tuning the code and the server after writing the application can solve many performance issues. From the start, you can build into the application design programming techniques for handling session variables. Designing these features from the start is much easier than trying to go back to an application and rewire it to use the new techniques.
End of Article
Prev. page
1
[2]
next page -->