ASP.NET MVC Multi site - where to store site configuration data

I am developing a multi-page ASP.NET MVC application (can host multiple sites from the same application instance application / multi-user application).

Earlier, I did this in a web form application and loaded the appropriate site configuration data (by checking the URL) in the page_load event on the user base page.

With ASP.NET MVC, will I be better at doing the same in Application_BeginRequest? Then I can add the configuration object to HttpContext.Current.Items.

+3
source share
2 answers

I'm doing something similar with the current system I'm working on.

URL-, , :

public class BaseController : Controller
{
    protected override void Initialize(RequestContext requestContext)
    {
        var host = requestContext.HttpContext.Request.Url.Host;
        Site = _siteService.GetSiteByHost(host);

        base.Initialize(requestContext);
    }       
}

Controller BaseController, Site Controller. , , , .

, , _siteService.GetSiteByHost(host). SiteService , , . :

public Site GetSiteByHost(string host)
{
    string rawKey = GetCacheKey(string.Format("GetSiteByHost by host{0}", host));

    var site = (Site)_cachingService.GetCacheItem(rawKey);

    if (site == null)
    {
        site = _siteRepository.GetSiteByHost(host);
        AddCacheItem(rawKey, site);
    }

    return site;
}

Session, , . Site , , SiteId . , , Site, Id. , .

+2

, asp.net-mvc

, , , , .

+2

Source: https://habr.com/ru/post/1763888/


All Articles