Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save enkelmedia/f3305ac3fb8cfd641f14edd98af820a0 to your computer and use it in GitHub Desktop.
Save enkelmedia/f3305ac3fb8cfd641f14edd98af820a0 to your computer and use it in GitHub Desktop.
public class RpSurfaceController : SurfaceController
{
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
var domains = ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem<List<DomainInfoDto>>(
"GenericTempStore-Domains",
() =>
{
var sql = @"SELECT [domainName],[languageISOCode] FROM [umbracoDomains] as d INNER JOIN [umbracoLanguage] as l on d.[domainDefaultLanguage] = l.[id]";
return ApplicationContext.Current.DatabaseContext.Database.Fetch<DomainInfoDto>(sql);
});
if(requestContext?.HttpContext?.Request?.Url != null)
{
var currentUrl = requestContext.HttpContext.Request.Url.AbsoluteUri;
foreach (var domain in domains)
{
if (currentUrl.StartsWith(domain.DomainName))
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(domain.LanguageISOCode);
}
}
}
base.Initialize(requestContext);
}
public class DomainInfoDto
{
public string DomainName { get; set; }
public string LanguageISOCode { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment