/// <summary> /// Called in the HTTP pipeline chain of execution when ASP.NET responds to a request. /// </summary> /// <param name="context">HTTP context.</param> public async Task Invoke(HttpContext context) { // Get root URL (e.g. "http://mydomain.com") string rootUrl = _webHelperService.GetRootUrl(); // Lookup domain details for this URL Domain domain = _domainService.ReadByUrl(rootUrl); Web web = _webService.Read(domain.TenantId); // Save domain details where they can be looked up throughtout the lifecycle of the HTTP request _webHelperService.SetItem <Domain>("RiversideCmsDomain", domain); _webHelperService.SetItem <Web>("RiversideCmsWeb", web); // Redirect if a redirect URL specified, otherwise invoke next action if (domain.RedirectUrl != null) { _webHelperService.Redirect(domain.RedirectUrl); } else { await _next.Invoke(context); } }