Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.net session variable counter not adding on

I have a master page with the following vb code in the code file...

Public Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

    If Not IsPostBack Then
        If Session("key") Is Nothing Then
            Session("key") = 0
        Else
            Session("key") = Session("key") + 1
        End If  
        Response.write(Session("key"))
        LoadData()
    End If

End Sub

This should write a number to the top of each page saying how many pages have been visited... It stays at zero all the time though.

Any ideas??

like image 284
Tom Avatar asked Jan 30 '26 14:01

Tom


2 Answers

Be sure to search your code in your master page and containing page for any Session.Abandon()

I ran into this problem a while back and didn't realise another developer had put that in.

like image 100
Jamie Taylor Avatar answered Feb 01 '26 02:02

Jamie Taylor


I've tested this and it works fine on my machine.

Ensure that your session timeout is set, otherwise it will expire resulting in Session("key") being set to 0 every Page_Load

Try adding the following to your web.config:

<configuration>
<system.web>
<sessionState timeout="120" />
</system.web>
</configuration>
like image 38
Curtis Avatar answered Feb 01 '26 03:02

Curtis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!