title: asp.net mvc5 global variables for all views
body: <p>I have fb,twitter and youtube urls in DB, and about 30 other application level variable.</p>
  
  <p>currently I am querying it in each action bcz in template I have social links in footer, if missed that will throw error.</p>
  
  <pre><code>ViewBag.Contents = db.Contents.Where(s =&gt; s.status == 1).OrderBy(s =&gt; s.group).ThenBy(s =&gt; s.sort).ToList();
  </code></pre>
  
  <p>I want above line to be executed for all action somewhere globaly.
  Googled for it, many people are suggesting to put in session but i think this should not go in session variables as its size may go long.</p>
  
  <p>All my controllers are inherited from <code>Controller</code> as</p>
  
  <p>public class HomeController : Controller{}</p>
  
  <p>please help.</p>
  
  <p><em>UPDATE</em>
   I have created constructor in home controller as  below</p>
  
  <pre><code>public HomeController()
      {
          if (ViewBag.Contents == null)
          {
              ViewBag.Contents = db.Contents.Where(s =&gt; s.status == 1).OrderBy(s =&gt; s.sort).ToList();
          }
      }
  </code></pre>
  
  <p>this reduced calling it in each action, but still I have to type the same in all controllers, Is this ok or not? and how can we write this globally for all controllers</p>