title: ASP.NET MVC How safe are static variables
body: <p>I want to ensure my website is capable of being hosted on the cloud in the future and also that it can handle a lot of requests.</p>
  
  <p>How safe are static variables?</p>
  
  <p>Are they unsafe because separate requests by separate users are actually sharing these static variables? Or is it because if you spread the site over threads/sharding or similar, (to handle high loads) the threads are sharing the static variables?</p>
  
  <p>Mainly I have helper classes, with static properties, should I change this architecture so that I instead create an instance of each class and access the instances?</p>
  
  <p>E.G Here is a sample of what I am doing:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using Mvc.Mailer;
  
  namespace MVCWebsite.Helpers
  {
          public class AppSettings
          {
                  public static void OnAppInit()
                  {
                          //General
                          AppName = "MyApp";
                          DesktopBaseURLs = new Dictionary&lt;string, string&gt;();
                          DesktopBaseURLs.Add("dev", "localhost:50560");
                          DesktopBaseURLs.Add("test", "www.test.whatever.com");
                          DesktopBaseURLs.Add("live", "www.whatever.com");
                          MobileBaseURLs = new Dictionary&lt;string, string&gt;();
                          MobileBaseURLs.Add("dev", "m.local.whatever.com");
                          MobileBaseURLs.Add("test", "m.test.whatever.com");
                          MobileBaseURLs.Add("live", "m.whatever.com");
  
                          //Emails
                          EmailHostName = AppName + ".com"; //For the moment atleast
                          NoReplyEmailAddress = "no-reply@" + EmailHostName.ToLower();
                          SupportEmailAddress = "support@" + EmailHostName.ToLower();
                          ErrorEmailAddress = "errors@" + EmailHostName.ToLower();
  
                          //Resources
                          TempFileURL = "/content/temp/";
                          UserDataURL = "/content/user-content/";
                          ProfilePicturesURL = UserDataURL + "profile-pictures/";
  
                          var a = GlobalHelper.GetURLAsServerPath(ProfilePicturesURL);
                          var b = a;
  
                  }
  
                  //General
                  public static string AppName { get; set; }
                  public static Dictionary&lt;string, string&gt; DesktopBaseURLs;
                  public static Dictionary&lt;string, string&gt; MobileBaseURLs;
  
                  //Emails
                  public static string EmailHostName { get; set; }
                  public static string NoReplyEmailAddress { get; set; }
                  public static string SupportEmailAddress { get; set; }
                  public static string ErrorEmailAddress { get; set; }
  
                  //Resources
                  public static string UserDataURL { get; set; }
                  public static string TempFileURL { get; set; }
                  public static string ProfilePicturesURL { get; set; }
  
                  //Methods
                  public static void SetAppURL()
                  {
  
                  }
          }
  }
  </code></pre>