Search code examples
asp.netapplication-poolstatic-variables

setting Application Pool idletimeout to 0 side effects


I have a web application running under IIS7. I am storing my global variables in a class with static variables. The class is called SessionVariables and inside it for example I have the following :

public class SessionVariables
{
    public static string PreferedColor= "Black"; 
}

I am setting this variable in another page AccountSettings.aspx where I have a dropdown with colors names. When the user selects a color , and clicks on save that's the code that is running.

   protected void btnSave_click(object sender, EventArgs e)
    {
    SessionVariables.PreferedColor= ddlColorNames.Text;
    }

if the application went idle for 5 minutes the static value of PreferedColor is always reset to default because the application pool settings was clearing the static values since the idle time-out (minutes) was set to 5. I changed it to 0 from IIS application pool and the problem disappeared, The application pool is not recycling anymore. I would like to know if there are any side effects for this setting.


Solution

  • Solved, it was a missing configuration in web.config that was clearing the static variables after 5 minutes I have added the following and all went well

    <sessionState mode="InProc" cookieless="false" timeout="480"/>
    

    and

     <forms loginUrl="~/Login.aspx"  slidingExpiration="true" timeout="480" />