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

  • SEARCH
  • Home
  • 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 452669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:05:44+00:00 2026-05-12T22:05:44+00:00

What is the best way to provide strongly typed access to the session object?

  • 0

What is the best way to provide strongly typed access to the session object? I am planning on turning on Option Strict, which is causing the compiler to complain about my lazy programming technique of directly accessing the session object:

Dim blah As Integer = Session("Blah")

My initial thought is to create a class that wraps the session and provides strongly typed properties for the information stored in the session. However, I cannot decide if the class should be a singleton, or instantiated on every use, or where the code should reside (i.e. within the web project or within a class library).

I’m leaning towards a singleton in my class library, but I don’t know if that is the best solution, or if I am missing any other possibilities.

Proposed Solution:

Public Class SessionAccess
    Public Shared Property Blah(ByVal session As HttpSessionState) As Integer
        Get
            Return Convert.ToInt32(session("Blah"))
        End Get
        Set(ByVal value As Integer)
            session("Blah") = value
        End Set
    End Property
End Class

Code Behind:

Dim blah As Integer = SessionAccess.Blah(session)
  • 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. Editorial Team
    Editorial Team
    2026-05-12T22:05:45+00:00Added an answer on May 12, 2026 at 10:05 pm

    Either my proposal is the “standard” way to do it, or else no one wraps their session access, since this question hasn’t received very many answers.

    I did find one line in this answer that mentioned creating a SessionManager:

    • Wrap the ASP.NET Session with a
      SessionManager to avoid development
      mistakes in spelling, etc. when
      referencing items from Session.

    I have not thought of any reason to not use a singleton class to provide typed access to the session, so that is the solution I went with in the project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, Trying to sort through the best way to provide access to my Entity
Him what would be the best way to provide a view where a user
I'm looking for some advice on the best way to provide a single place
What is the best way to provide an asynchronous service interface to multi-platform (primarily
Rephrase of question: What is the best way to provide alternate stylesheets for a
I'm trying to decide the best way to provide templates for a bunch of
I think the best way to ask this question is to provide an example.
This is a very general open question What is the best way to provide
Possible Duplicate: Best way to provide charts on the web? Server-side or client-side library?
What is the best way to provide Azure Table data to a Silverlight 5

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.