Back to
swartzentruber.net
 

Code Examples in VB.NET (Framework 1.1)

Code Samples Home


cachemanager

createlinkspagewithxml

hideorshowaddnew

lookupusercontrolwithevents

lookupusercontrolwithevents2

looplistboxforselected

tourcalendarinternational

tourcalendarwithdetail

tourcalendarwithdetail2

tourcalendarwithdetail3

usercontrol_sessionview

usertablestoarraylist_via_sqldmo

User control - Display all session variables
Summary & Comments

This is just a very simple user control that you can throw on pages in development to keep track of current session variables. For instance, when doing a shopping cart "checkout" it is helpful to know what information you have collected so far and confirm that those values are valid.

Added 3/23/02

ASPX Code
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="SessionView.ascx.vb" Inherits="swartzentrubernet.SessionView" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:Label id="LblSessionVars" runat="server"></asp:Label>

VB.NET Codebehind Code
Option Strict On
Option Explicit On

Imports System.Text
Imports System.Web
Imports System.Web.HttpContext

Public MustInherit Class SessionView
    Inherits System.Web.UI.UserControl
    Protected WithEvents LblSessionVars As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
     Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        ' this control should only be used in development to keep
        ' track of sessions. it should not be used on a production server
        ' for security reasons

        Dim cur As HttpContext = HttpContext.Current
        Dim vars As StringBuilder = New StringBuilder("<table><tr><th>Key</th><th>Value</th></tr>")
        Dim k As String

        For Each k In cur.Session.Keys
            vars.Append("<tr><td>")
            vars.Append(k)
            vars.Append("</td><td>")
            vars.Append(cur.Session.Item(k))
            vars.Append("</td></tr>")
        Next
        vars.Append("<tr><th colspan=2>Current Session Variables</th></tr>")
        vars.Append("</table>")
        LblSessionVars.Text = vars.ToString
    End Sub

End Class

KeyValue
Current Session Variables

© 1999-2008 swartzentruber.net