title: Prevent caching on Custom Display Name Attributes in MVC
body: <p>I have a Custom Display Name attribute that translates the field names based on the user's language preference.  Unfortunately what happens is that the first user's language preference is cached for every subsequent request regardless of the subsequent user's language preference.  The result is that the page content, header, and menu items display in the proper language, but only the labeled fields display with the incorrect language.</p>
  
  <p>Here is part of the View Model I'm using:</p>
  
  <pre><code>public class RegisterViewModel
  {
      [CustomEmailAddress]
      [CustomDisplayName("lbl_email")]
      public string Email { get; set; }    
      [CustomRequired]
      [CustomDisplayName("lbl_fn")]
      [StringLength(255)]
      public string FirstName { get; set; }    
      ...
  }
  </code></pre>
  
  <p>Here is the Custom Display Name attribute:</p>
  
  <pre><code>public class CustomDisplayNameAttribute : DisplayNameAttribute
      {
          public CustomDisplayNameAttribute(string value = "")
              : base(GetMessageFromResource(value))
          {
          }
  
          private static string GetMessageFromResource(string value)
          {
              string CurrentUser;
              try
              {
                  CurrentUser = HttpContext.Current.User.Identity.Name;
              }
              catch
              {
                  CurrentUser = "";
              }
              string lang = ModelInit.repo.LangCode(CurrentUser);
              string ItemLegend = ModelInit.repo.TranslateItem(value, lang);
              return ItemLegend;
          }
      }
  </code></pre>
  
  <p>While debugging the problem, I found that MVC does NOT bother to hit the "CustomDisplayNameAttribute" class on subsequent requests even after the user logs off and a new user logs on.  So I also tried decorating the Custom Display Attribute with: </p>
  
  <pre><code>[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)]
  </code></pre>
  
  <p>but it didn't work either.  If this behavior can't be changed (because it's built-in to the framework) then is there a way to clear the cache from the Custom Display Name attribute when the user logs off?  (Actually, this would be my preferred solution!) Right now, the only way to clear it is by stopping and restarting the program.</p>