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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:10:46+00:00 2026-06-01T18:10:46+00:00

I have an ASP.Net 4.0 website on a shared hosting system. Applications are recycled

  • 0

I have an ASP.Net 4.0 website on a shared hosting system. Applications are recycled after 20 minutes of inactivity.

In my application some static variables are initialized in application_start.

When the next request comes in, the application should be restarted, application_start executed and the static variables reset.

After the period of inactivity, when I access pages that depend on the static vars, they are null and that creates errors.

Since these variables are initialized in application_start, it seems odd that after the period of inactivity that they would be null since the application restarting would reinitialize them.

In fact, when I see the null reference errors, recycling the app pool (and executing application_start) solves the problem until the next time the application is dropped from memory.

I’m wondering if some other type of system memory problem is occurring when the application is removed from memory, because if the application was simply being recycled, the reinitialization of the static variable in application_start would mean there would be no reason for the statics to be null.

Since static variables are not garbage collected they should never be null after initialization.

The errors never occur on any developer machines, only on the shared hosting system. What could be some other causes for static variables initialized in application_start to become null?

There is no code that resets the variables. They are private fields that only contain access via a get method.

Code:

private static List<State> stateList;

public static void LoadStaticCache()
{
    var service = DependencyResolver.Current.GetService<ILocationService>();
    stateList = service.GetAllStates().ToList();
}

public static List<State> GetStates()
{
   return stateList;
}

When the inactivity period is met, the next time the stateList is accessed, it is null.

However, it is always initialized in application_start. How can it ever be null unless it is a system problem?

    protected void Application_Start()
    {
        StaticCache.LoadStaticCache();
    }

Recycling the Application Pool fixes the issue 100% of the time.

  • 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-01T18:10:48+00:00Added an answer on June 1, 2026 at 6:10 pm

    It sounds like your issue is related to session timeout.

    Unlike earlier versions of IIS, if your hosted server is running IIS 7.0 or higher with Integrated Mode, Application_Start will not have access to the current HTTP context since it doesn’t exist yet. IIS 7.0 in Classic Mode will have no issues.

    In either case, a solution would be to move your initializations to Session_Start in Global.asax:

    //protected void Application_Start()
    //{
    //    StaticCache.LoadStaticCache();
    //}
    
    protected void Session_Start(object sender, EventArgs e) 
    {
        StaticCache.LoadStaticCache();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.Net MVC 3 Website hosted on a shared Windows hosting package.
assume the hypothetical case of a small ASP.NET website on a shared hosting (up
I have a domain xyz.com on an ASP.NET shared hosting environment. I am confused
I have written 3 ASP.net MVC web applications, and all are deployed on shared
i have an ASP.NET application (website, catalog-like). No high load expected (not more than
I have a SQL Server database which is shared between several ASP.NET (VB.NET) websites,
I have an ASP.NET website containing the following <asp:UpdatePanel ID=UpdatePanel1 runat=server > <ContentTemplate> <asp:Label
I have an asp.net website (SQL Server, Windows 2003, IIS 6) and I am
I have a ASP.NET website deployed under IIS uisng virtual directories. I'm using forms
I have a ASP.NET Website (.NET 2 IIS 5.1) running on machine A with

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.