View Full Version : Cannot add anything to Session State
I am having a BIG problem using Session Variables in my site.
The site works perfectly on my local machine (using IIS.)
However, when I upload the files to my web site, the Session Variables are not created. Nothing is getting written to the session state.
The session variable is not a simple string or number,but a hashtable. Other pages I have that usesession variables that are strings work fine.
I should be able to easily add a hashtable to session state! It works perfect on my end. Why doesn't it work on my DiscountASP.Net site???
-- Lee
bluebeard96
11-19-2004, 03:39 AM
Sample code? Not sure if this example might help (if this is a syntax issue):
// Create the hashtable...
m_StoredObjects = new Hashtable();</o:p>
// Add whatever data you want, then
//Create thesession variable (pointer)
Session.Add("storedObjects",m_StoredObjects);
// Read the hashtable</o:p>
</o:p>
m_StoredObjects = (Hashtable) Session["storedObjects"];
http://www.sadeveloper.net/Articles_View.aspx?articleID=152
</o:p>
Mike Reilly, Secretary/Webmaster
Kiwanis Club of Rancho Penasquitos
"Serving the Children of the World"
Mike@KiwanisPQ.org
(760) 419-7429
Thanks for the reply, but as I pointed out, my code is already working fine.
I'm pretty sure it's something on the discountasp.net server that won't allow the hast=htable to be stored in a session variable.
For what it's worth, here is my code (VB):
'declare globals
Dim blnUpdate as Boolean
'this Load script prevents popularity count from being run up by repeated refreshes
Sub Page_Load(Src As Object, E As EventArgs)
If dsdetail.RecordCount <> 0
Dim colViewed as HashTable = New HashTable 'to store name and title
Dim strDocID, strTitle as String
strDocID = dsdetail.FieldValue("DOC_ID", Nothing)
strTitle = dsdetail.FieldValue("TITLE", Nothing)
If Session("ArticlesViewed") Is Nothing Then 'session variable does not exist
colViewed.Add(strDocID,strTitle) 'add this doc id and title to the collection
Session("ArticlesViewed") = colViewed 'create session variable, store hashtable in it
blnUpdate = true 'update access count
Else 'session variable does exist
colViewed = Session("ArticlesViewed") 'set collection to existing session variable
If colViewed.Contains(strDocID) Then 'the collection contains this doc id
blnUpdate = false 'do not update access count
Else 'session variable does NOT contain this doc id
colViewed.Add(strDocID,strTitle) 'add this doc id and title to the collection
blnUpdate = true 'update access count
Session("ArticlesViewed") = colViewed 'store updated collection to session
End If
End If
End If
End Sub
I figured out what was happening.
I am using Dreamweaver to develop this site. With Dreamweaver, the data binding takes place "behind the scenes", so to speak, during the page load.
My code to add the hashtable to session state has a condition to only create the session variable IF the dataset has records in it:
If dsdetail.RecordCount <> 0
As I said, this works fine on my local server, because on my server the Dreamweaver databinding creates the dataset BEFORE the Page_Load event,and so the RecordCount is greater than 0.
However, when I uploaded the exact same page to the DiscountASP server, it did not work. For some reason, on DiscountASP,the Dreamweaver tag onlydatabinds AFTER the Page_Load event. Because the dataset was not created before Page_Load, the session variable never got created.
I added a DataBind() command at the top of Page_Load,and so now it appears to work. It appears as though this is partly a Dreamweaver issue, then.
Does anyone know why, on my end,Dreamweaver databinding would execute BEFORE Page_Load, and in DiscountASP, AFTER Page_Load?
vBulletin® ©Jelsoft Enterprises Ltd.