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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:08:20+00:00 2026-05-15T08:08:20+00:00

I want to store a small list of a simple object (containing three strings)

  • 0

I want to store a small list of a simple object (containing three strings) in my ASP.NET MVC application. The list is loaded from the database and it is updated rarely by editing some values in the site’s admin area.

I’m thinking of using HttpContext.Current.Application to store it. This way I can load it in the Global.asax:

protected void Application_Start()
{
    RegisterRoutes(RouteTable.Routes);

    HttpContext.Current.Application["myObject"] = loadDataFromSql(); // returns my object
}

And then can easily reference it from any controllers or views as needed. Then in the event, the admin area calls the updateMyObject controller action, I can just update the DB and load it in again and replace HttpContext.Current.Application["myObject"].

Are there any cons to doing this? It seems like it will work fine for what I am trying to achieve, however does anyone know of a better way to do this, assuming there is some major disadvantage to the method I’ve laid out?

  • 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-15T08:08:21+00:00Added an answer on May 15, 2026 at 8:08 am

    What you actually do is Caching, and it’s great, since you reduce calls to an external storage (a database or a file, whatever). The trade-off is memory usage, of course. Now, almost any modern web framework, including ASP.NET, includes some kind of a caching mechanism. Either you use it, or you use some kind of a global variable.

    Storing data in ASP.NET’s built-in Cache object has some significant advantages, since this mechanism actually checks the memory usage and removes the cached data according to some rules.

    However, if the data you want to cache is intensively used across the application, and its size is not too large (say, smaller than 1 MB), you may want to store it in as a global variable.

    In ASP.NET, global variables are achieved by either using the Application object, like you described in your question, or by writing public static properties/fields in an internal/public class.

    Here’s my solution to static properties. Note that I use a locking object, to protect the inner data from corruption. It looks like this:

    public class WhateverClass
    {
      private static object theLocker = new object();
      private static YourDataType theData;
      public static YourDataType TheData
      {
        get
        {
          lock (theLocker)
          {
            return theData;
          }
        }
        set
        {
          lock (theLocker)
          {
            theData = value;
          }
        }
      }
    }
    

    The usage is very simple:

    First time, in Application_Start:

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    
        WhateverClass.TheData = loadDataFromSql();
    }
    

    In any controller:

    var myData = WhateverClass.TheData;
    

    This approach is better because you have type safety, since this public static property can be explicitly declared with the exact type. In addition, this kind of storage is more testable since it doesn’t depend on the web context.

    HTH!

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

Sidebar

Related Questions

I have a hash table that I want to store to disk. The list
I'm trying to create a simple animation. Long story short, I've got a list
I have a list of requirements for a software project, assembled from the remains
I have a decision to make. I want to write a list of names
I have a list of vectors (in Python) that I want to normalize, while
Hello I use glade to write a small gtk application. the application includes a
I have a list of String s, and I want to concatenate them with
For a personal project, I want to record a stream of unrelated events, to
Given a list name User Data and setting Item-Level Permissions to Only their own
I'm writing a small app with the help of Eclipse while learning Swing GUIs

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.