I’m developing an ASP.NET MVC multi site application (can host multiple sites from the same application instance / multi-tenant application).
I’ve previously done this in a web forms application and loaded up the appropriate site configuration data (by inspecting the url) on the page_load event of a custom base page.
With ASP.NET MVC would I be best to do the same in Application_BeginRequest? I can then add the configuration object to HttpContext.Current.Items.
I’m doing something similar with the current system I’m working on.
I’m determining the site by the url the user accesses the application as follows:
Every
Controllerthen extendsBaseController, so theSiteobject is available to everyController. If you have any more specific questions, ask and I’ll let you know what we did.update
What you see above is
_siteService.GetSiteByHost(host).SiteServicehas a caching layer between it and the Repository, which takes care of all the cache related stuff. it is defined as:We try not to use the
Sessionunless we’re dealing with simple data types, like an integer. I wouldn’t store aSiteobject in the Session, but I would store an integer that represents theSiteIdin the session. Then the next time the user accesses the application, I can get theSiteobject that’s associated with the current user from the cache by Id. In the case above though that’s not necessary.