Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 104405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:16:35+00:00 2026-05-11T01:16:35+00:00

instead of doing session(myvar1) = something session(myvar2) = something session(myvar3) = something session(myvar4) =

  • 0

instead of doing

 session('myvar1') = something  session('myvar2') = something  session('myvar3') = something  session('myvar4') = something 

is doing

enum sessionVar    myvar1    myvar2    myvar3    myvar4 end enum    session(sessionVar.myvar1.tostring) = something  session(sessionVar.myvar2.tostring) = something  session(sessionVar.myvar3.tostring) = something  session(sessionVar.myvar4.tostring) = something 

would be better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:16:36+00:00Added an answer on May 11, 2026 at 1:16 am

    Instead of using constants for the session keys, I’m using my own type-safe session object, which looks like this (sorry this is in C#, see below for a VB version):

    public class MySession {   // Private constructor (use MySession.Current to access the current instance).   private MySession() {}    // Gets the current session.   public static MySession Current   {     get     {       MySession session = HttpContext.Current.Session['__MySession__'] as MySession;       if (session == null)       {         session = new MySession();         HttpContext.Current.Session['__MySession__'] = session;       }       return session;     }   }    // My session data goes here:   public string MyString { get; set; };   public bool MyFlag { get; set; };   public int MyNumber { get; set; }; } 

    Whenever I need to read/write something to/from the session, I can use my typesafe session object like this:

    string s = MySession.Current.MyString; s = 'new value'; MySession.Current.MyString = s; 

    This solution results in several advantages:

    • I have a typesafe Session (no more type-casts)
    • I can document all session based data (by commenting the public properties in MySession)
    • When adding a new element to the session, I don’t have to search the solution to check if the same session-key was already used somewhere else.

    Update: Here’s a VB version (automatically converted from the C# version). Sorry, but I don’t know VB and so I didn’t know how to write the properties in VB:

    Public Class MySession     ' Private constructor (use MySession.Current to access the current instance).     Private Sub New()     End Sub      ' Gets the current session.     Public Shared ReadOnly Property Current() As MySession         Get             Dim session As MySession = TryCast(HttpContext.Current.Session('__MySession__'), MySession)             If session = Nothing Then                 session = New MySession()                 HttpContext.Current.Session('__MySession__') = session             End If             Return session         End Get     End Property      ' My session data goes here:     Public MyString As String     Public MyFlag As Boolean     Public MyNumber As Integer End Class 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 83k
  • Answers 83k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're using C# 3, try this: int[] array =… May 11, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer Z-Scale and perspective is for WPF-based (windows) XAML interfaces, SL2… May 11, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure if using MySQL build in encryption would… May 11, 2026 at 4:49 pm

Related Questions

I'm not too familiar with generics (concept or the syntax) in general (short of
I watched a pdc session by Stephen Walther and in the presentation he was
I know this isn't strictly a programming question but y'all must have experienced this.
I've got several function where I need to do a one-to-many join, using count(),

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.