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 3499054
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:33:54+00:00 2026-05-18T12:33:54+00:00

When i started developing web applications i stored the authentication details of the user

  • 0

When i started developing web applications i stored the authentication details of the user in two session variables

 Session["UserName"]="username";
 Session["Password"]="paswword-123";

But someone proposed me an idea to create a class which holds the UserName and Password properties and on succesful authentication i have been asked to create an instance of the class and set the UserName and Password properties and store that instance in the session.

I have been told that the session object is TypeSafe. Can someone explain what is typesafe coding and the advantage of storing the object in the 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-18T12:33:54+00:00Added an answer on May 18, 2026 at 12:33 pm

    Basically, the classic approach of storing values directly in Session["something"] has two drawbacks:

    • Magic strings: If you mistype something, your code compiles fine but you get either a runtime error or, worse, an unnoticed bug in your code.
    • Casting: After reading Session["something"], you need to cast it to the type you need. (This is what is meant by “not type-safe”.)

    Using a strongly-typed object that is stored in the Session eliminated the second problem. Well, actually, your custom object still needs to be cast, but it’s only one cast instead of two (or ten) casts, which reduces the likelyhood of something going wrong. Again, a wrong cast is something which is only detected at run-time.

    Another approach is to encapsulate the access to Session variables in static properties:

    public class MySession {
        public static string UserName {
            get { return (string)HttpContext.Current.Session["UserName"]; }
            set { HttpContext.Current.Session["UserName"] = value; }
        }
    }
    

    Of course, both approaches can be combined, allowing you to group related properties (UserName and Password) in a common object.

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

Sidebar

Related Questions

I am looking to get started with developing web applications/services in C# and ASP.NET.
Using JDeveloper , I started developing a set of web pages for a project
Our team is developing a rather big ASP.NET web project which initially started in
I've recently started developing applications for the Blackberry. Consequently, I've had to jump to
With Google TV around the corner, I started thinking about developing a web application
I have quite a few years experience of developing PHP web applications, and have
We are currently developing a few web applications and are letting our designers convert
I am trying to get started developing using the .NET Micro Framework but appear
I have found the Getting Started documents for developing apps on iPhone. I wanted
This is a weird problem I have started having recently. My team is developing

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.