title: Is this code thread safe in ASP.NET MVC 4?
body: <p>Based on my current understanding I do not think this code is thread safe but want to confirm. In other words I think that, although it would be extremely unlikely, multiple threads representing different HTTP requests could potentially mix up the value of the <code>_userName</code> property.</p>
  
  <pre><code>public class SomeClass
  {
      private static string _userName;
  
      public static string UserName
      {
          get
          {
              if (string.IsNullOrEmpty(_userName))
              {
                  _userName = HttpContext.Current.User.Identity.Name;
              }
  
              return _userName; 
          }
      }
  }
  </code></pre>
  
  <p>Is it thread-safe and if not would removing the null check, and always accessing <code>HttpContext.Current.User.Identity.Name</code> directly (in a static property) be thread-safe?</p>
  
  <pre><code>public class SomeClass
  {
      public static string UserName
      {
          get
          {
              return HttpContext.Current.User.Identity.Name; 
          }
      }
  }
  </code></pre>