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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:32:26+00:00 2026-06-18T11:32:26+00:00

There are numerous posts available on alternatives to global state, but I have lingering

  • 0

There are numerous posts available on alternatives to global state, but I have lingering questions regarding implementation in a web environment.

In ASP.NET, values stored in the session are practically global variables, but it seems you can’t reasonably store, e.g., authenticated username, permissions, etc. across pages and events without resorting to the Session[] collection. (I would typically use dependency injection, but you wouldn’t want to pass these values in the viewstate/url to the client.)

So I take that global state is a necessary evil in web development (due to the stateless nature of HTTP) and the answer is to just use it responsibly. What is a good facade pattern for implementation? A static class such as the one below that just gets and sets values in the session doesn’t do much to mask the global state.

public class SessionWrapper
{
    public static string UserName
    {
        get { return Convert.ToString(Session["UserName"]); }
        set { Session["UserName"] = value; }
    }
    public static bool IsAuthenticated
    {
        get { return Convert.ToBoolean(Session["IsAuthenticated"]); }
        set { Session["IsAuthenticated"] = value; }
    }
}
  • 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-06-18T11:32:28+00:00Added an answer on June 18, 2026 at 11:32 am

    Global variables are problematic but global values are fine. So if you want to mitigate the “problems” of global state simply make those objects immutable (I don’t see how DI is all that relevant).

    The User property of the HttpContext object is useful for storing such state since it needs to be available to every part of your application but can only be assigned early in the pipeline.

    So, just come up with your own implementation of System.Security.Principal.IPrincipal that has the extra properties you want and assign it to HttpContext.Current.User during, say, the AuthenticateRequest event.

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

Sidebar

Related Questions

There have been numerous posts on string algorithms: Algorithm to find articles with similar
I've read through numerous posts here regarding mysql2, but although the gem seems to
I have looked at numerous posts which state various ways in which to remove
I have seen numerous posts about the IE Webpage has expired error message, but
I know there are numerous posts out there for a similar problem, but mine
There are numerous post regarding LINQ and multiple joins. I have however not found
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There's a number of posts here on hashing of passwords and numerous recommendations on
I hesitate to ask, as there are numerous other posts on this topic (
I've checked numerous other SO posts and MySQL docs but can't seem to get

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.