title: MVC3 load common data for views
body: <p>I am developing an MVC3 "movie list" application containing several "sites" depending on the request hostname.</p>
  
  <p>I am trying to use a strongly typed ViewModel like this (examples are simplified to get to the essence of the question):</p>
  
  <pre><code>class ViewModelBase
  {
    public int siteId { get; private set; }
  
    public ViewModelBase(DbContext db)
    {
      siteId = &lt;here I want to make a db-lookup based on the request hostname&gt; &lt;== This is my problem
    }
  }
  
  class MoviesIndexViewModel : ViewModelBase
  {
    public List&lt;Movie&gt; movies { get; private set; }
  
    public MoviesIndexViewModel(DbContext db) : base(db)
    {
      movies = db.Movies.where(m =&gt; m.SiteId == siteId).ToList();
    }
  }
  </code></pre>
  
  <p>An my controller would then just do this:</p>
  
  <pre><code>public class MoviesController : Controller
  {
    public ActionResult Index()
    {
      var model = new MoviesIndexViewModel(new MySpecialDbContext());
      return View(model);
    }
  }
  </code></pre>
  
  <p>Question is: How will I get the "request host header" into the code line shown above? I know how to make the actual DB-lookup, but can I just access any request parameters here? Or should I supply something through parameters to the constructor?</p>