Web Analytics Made Easy -
StatCounter Checking 'Session' - CodingForum

Announcement

Collapse
No announcement yet.

Checking 'Session'

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checking 'Session'

    Hello

    What is the best way, please, of checking that the vb.net code I have for 'Session' is actually working?

    The code in my myLogon.aspx.vb is as follows:

    Code:
    Imports System.Web.SessionState 'stores data specific to one user 
    Imports System.Web.SessionState.HttpSessionState
    Imports System.Web.HttpContext
    'Imports System.Web.HttpContext.Current.Session
    
    Protected Sub LogonBtn_Click(sender As Object, e As EventArgs) Handles LogonBtn.Click
    
            'Authenticate user
    
            Dim Authenticated As Boolean = Authenticate(strEmailTextBox.Text, passwordTextBox.Text)
    
            'If authenticated, send user to userpage.aspx
    
            If Authenticated Then
    
                Dim target = String.Format("~/userpage.aspx?strEmailValue={0}", strEmailTextBox.Text)
    
                [B][COLOR="#FF0000"]Session("strEmailValue") = strEmailTextBox.Text[/COLOR][/B]
    
                Response.Redirect(target, False)
    
            Else
    
                LabelError.Text = "Email/Password invalid. Login denied"
    
                LabelError.Visible = True
    
            End If
    
        End Sub
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            'If Session("strEmailValue") Is Nothing Then
            'Response.Redirect("~/index.aspx")
            'Else
    
            [B][COLOR="#FF0000"]Dim strEmailValue As String = Session("strEmailValue")[/COLOR][/B]
    
            'End If
    
            End Sub
    The code I have for userpage.aspx.vb:

    Code:
    Protected Sub btnLogout_Click(sender As Object, e As System.EventArgs) Handles btnLogout.Click
    
         [B][COLOR="#FF0000"]Session.RemoveAll()
            Session.Clear()
            Session.Abandon()[/COLOR][/B]
            Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1))
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.Cache.SetNoStore()
            Response.Redirect("/Account/myLogon.aspx")
    
        End Sub
    strEmailValue is the variable that is, the user's unknown email address
    strEmailTextBox.Text is the ID of the email field in my log-in form

    I have not made changes to my Web.config file, so the 20 minute default should apply.

    Thanks for any advice.
    Last edited by Blue1; Sep 10, 2016, 10:55 PM.
Working...
X