Hi!
I appear to have a similar problem to this post. I am following (and reproducing in my own VWD) the Video Lesson 03 with regards to userCount and postback. I am an absolute beginner (began VWD this morning - it is now 5pm Australia time). The beginner videos I am using are from:
http://msdn.microsoft.com/vstudio/express/vwd/learning/
(different site from the the original message of this thread).
My userCount also does not appear to work. I have checked and rechecked my version with the video, but the outcome (in running/debugging) differs. And the outcomes in IE7 and FireFox (both not appropriate) also differ from each other. Here is the code I have used.
Global.asax
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Application(
"userCount") = 0
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Application(
"userCount") += 1
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
Application(
"userCount") -= 1
End Sub
I added (as per the video) the initialisation value for Application_Start as 0
I added the session count as incrementing by 1 in Session_Start
I added the session count as decreasing by 1 in Session_End
aspx.vb
Protected
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
TextBox1.Text =
""
End If
Page.Response.Write(
"User Count is: " & Application("userCount").ToString())
End Sub
I added (as per video) the second last line here to provide the count for me on running/debugging.
Now...The code as per the video all makes sense to me, and it was tested on the video (to increment as a new browser was opened - he opened three - then refreshed the previous two, which reverted to show that 3 browsers were open). This appeared fine on the video; however, when I attempted to do the same thing, MINE didn't work. My default browser is FireFox (I love the tabbed browsing and IE7 appears to have bugs in terms of recognising the allowance of cookies!! and often tells me that a website is non-existant, whereas FireFox can always find it - therefore I flip between the two). In debugging, FireFox is initiated, but regardless of the number of tabs or windows opened (I tried both), the userCount is 1 and does not increment. Then, when I open IE7, (with several FireFox browsers still open) the count always starts at 2 regardless of the number of FireFox browser windows open. When I open more tabs or windows (I tried both) in IE7 the numbers increment appropriately; however, when I go back to a previous IE7 tab and refresh it, the count continues to increment from the last browser open, rather than simply reflect the actual number of browsers open. This is difficult to explain...in other words, if I have 3 IE7 browsers open (the last says "User Count is 3", then return to the first browser and refresh it the new message reads "User Count is 4" - even if only 3 windows were ever opened. Now, that did not occur on the video.
OK, I did notice the comment in the code stating that Session_End will only express if SessionStateMode is InProc. I figured this as a possible reason but I had no idea what this meant, so I consulted the Help system, where it stated that InProc is the default for VWD. Furthermore, it stated that InProc required StateServer mode with instructions for changing this, then "Set the mode attribute of the sessionState element to SQLServer", where "sessionState" leads to another set of instructions for changing this. In fact this is the very page that you have referred the thread originator to (the other thread no longer exists).
The thread originator appeared to be querying that the number of users did not DECREASE when browsers were closed and remaining ones refreshed. This is NOT my problem - I also noticed this, of course, but my initial replay of the video enlighted me that HE didn't test the DECREASE of users either. He simply says that we would have to wait for 20 minutes to see the decrease - that's fine.
Now, I am an absolute beginner
, so most of the HELP file was Double-Dutch to me. I only described it in order to demonstrate my attempted at finding my own solutions in order to cancel out reiterations of what I HAD discovered (amongst the Double-Dutch).
Now, from my experiences, I can guess that the system sees 1 FireFox user regardless of actual FireFox users (and perhaps that is because all windows were opened on the one computer???). But I would have thought that IE7 would have been without error or problem. Also, if the Session_End system does not recognise the number of FireFox users, the number of users count isn't going to be very practical is it? Lots and lots of people use FireFox.
Could I have answers to:
- Do I have any misunderstandings or misconceptions evident in this post (remember, absolute beginner)?
- Is there an error or problem in the code?
- Why doesn't FireFox increment?
- Why does IE7 continue to increment inappropriately?
- Why do the two browsers react differently, anyway?
- Regarding your statement, "Seems unless you call Session.Abandon() or session timeout it never fires.", is this the answer? If so, could you provide me with the exact code and tell me were I would place this? Would this be an alternative to the userCount decrease code in Session_End?
Please remember that I am an absolute beginner - hence, could I have a replay without jargonistic language.
Thankyou in advance for any help,
Fran...