问题
Im sure it has nothing to do with persistance across Multiple Computers but seems quirky that a second website visit, would trigger a refresh of question & answers that are dynamically loaded to be displayed within a Ajax update panel.
Session Interaction and logging
Web.Config: <sessionState mode="InProc" cookieless="UseCookies" timeout="20" cookieName="ASPNET_Quiz" />
Global.asax:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("test") = "true" 'Used only to create a static Session ID for references.
If (Globals.Quiz(Session) Is Nothing) Then
Globals.Quiz(Session) = New classes.Quiz(WebConfigurationManager.OpenWebConfiguration("~"))
End If
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Globals.Quiz(Session) = Nothing
Session.Remove("test")
Session.Abandon()
End Sub
Globals.vb
Module Globals
'Get/Set a Quiz object into the SessionState.
Public Property Quiz(sess As HttpSessionState) As Quiz
Get
Return CType(sess("quiz"), Quiz)
End Get
Set(value As Quiz)
sess("quiz") = value
End Set
End Property
End Module
I have a Master Page with an UpdatePanel that is used to countdown a number of minutes, based on a Database value, and is AsyncPostBack triggered off a Timer Tick event (Interval=1000)
The Content Page has a different UpdatePanel wrapped around the Question & Answers for the site, and also has a AsyncPostBack trigger registered (through the codebehind) to the built RadioButtonList's SelectedIndexChanged event.
If only one person is accessing the site, then there is no problem. As soon as another user accesses the site, is when the Questions & Answers get reshuffled in the Quiz object, which then reshuffles their display and basically causes Questions that have not been answered to be displayed either above the users current position or below. The Answers that have been selected already, do not change but the order of the Answers is reshuffled. The Randomization of the Q&A is rooted at the SQL Server side, via SProc.
Updated 2012-12-07
- Changed all 3 of the code segments above to mirror my current design
- Also, not sure if it matters but changed the Content Page UpdatePanel PostBackTrigger from
AsyncPostBack
to just aPostBack
Question:
- Any suggestions for fixing this? If it matters any, i also incorporated PageRouting for the site.
- Is there a better approach for storing .Net objects, so they survive postbacks? Key is that the Questions & Answers classes associated with the Quiz object, are dynamically ordered every time the Sproc is called. So i need to keep them in the same order as they are first presented.
- Should i be initializing the Quiz object in
Application_BeginRequest
instead ofSession_Start
?
来源:https://stackoverflow.com/questions/13751893/session-state-persists-across-multiple-computers