[.NET] 顯示20分鐘內線上的人數
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Title = "7-3"
Session.Timeout = 1
If Session("population") Is Nothing Then
Session("population") = 1
Else
Session("population") += 1
End If
Session.Timeout = 20
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs)
Label1.Text = Label1.Text & Session("population")
End Sub
如果是用session寫的話,那麼ie一關就又變成1了,所以我改用application寫,如下
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Title = "7-3"
Session.Timeout = 20
If Application("population") Is Nothing Then
Application("population") = 1
Session("population") = Application("population")
Else
Application("population") += 1
Session("population") = Application("population")
End If
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs)
Label1.Text = Label1.Text & Session("population")
End Sub
這樣寫的話,是沒辦法將時間控制在20分鐘內,人數會一直增加,不知道我該改那裡呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.123.1.3