title: Prevent caching of layout file in MVC when caching Index action method
body: <p>I have many create Views in my MVC application. I have cached the <code>GET</code> <code>Index</code> action method using <code>[OutputCache]</code> annotation, so that the view is stored in the cache.</p>
  
  <p>I store the details about the currently logged in user in the <code>Session</code>, and display the user's first name in the layout after reading it from the <code>Session</code>.</p>
  
  <p>The problem is, since I have cached the views, the layout is also cached. So even if a different user logs in, the first name of the previous user is visible, because the layout was cached last time.</p>
  
  <p>Is there any way to prevent caching of the layout? Or is there any other way I can stop the first name display from getting cached?</p>
  
  <p>I thought about using <code>VaryByCustom</code>, but I am not sure what to do in the <code>GetVaryByCustomString</code> method that I will need to override.</p>
  
  <p>What would be the best approach to prevent caching of the layout, or alternately, varying the cache by user?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I must clarify that I am using my own custom user management logic. I have my own Users table in the database and I retrieve relevant data on login and store it in <code>Session</code>.</p>