optimizing tenant resolution and routing
This commit is contained in:
@ -8,7 +8,6 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Oqtane.Repository;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -18,21 +17,18 @@ namespace Oqtane.Pages
|
||||
public class HostModel : PageModel
|
||||
{
|
||||
private IConfiguration _configuration;
|
||||
private readonly SiteState _state;
|
||||
private readonly IAliasRepository _aliases;
|
||||
private readonly ITenantManager _tenantManager;
|
||||
private readonly ILocalizationManager _localizationManager;
|
||||
private readonly ILanguageRepository _languages;
|
||||
|
||||
public HostModel(
|
||||
IConfiguration configuration,
|
||||
SiteState state,
|
||||
IAliasRepository aliases,
|
||||
ITenantManager tenantManager,
|
||||
ILocalizationManager localizationManager,
|
||||
ILanguageRepository languages)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_state = state;
|
||||
_aliases = aliases;
|
||||
_tenantManager = tenantManager;
|
||||
_localizationManager = localizationManager;
|
||||
_languages = languages;
|
||||
}
|
||||
@ -54,19 +50,14 @@ namespace Oqtane.Pages
|
||||
// if culture not specified and framework is installed
|
||||
if (HttpContext.Request.Cookies[CookieRequestCultureProvider.DefaultCookieName] == null && !string.IsNullOrEmpty(_configuration.GetConnectionString("DefaultConnection")))
|
||||
{
|
||||
var uri = new Uri(Request.GetDisplayUrl());
|
||||
var hostname = uri.Authority + "/" + uri.LocalPath.Substring(1);
|
||||
var alias = _aliases.GetAlias(hostname);
|
||||
var alias = _tenantManager.GetAlias();
|
||||
if (alias != null)
|
||||
{
|
||||
_state.Alias = alias;
|
||||
|
||||
// set default language for site if the culture is not supported
|
||||
var languages = _languages.GetLanguages(alias.SiteId);
|
||||
if (languages.Any() && languages.All(l => l.Code != CultureInfo.CurrentUICulture.Name))
|
||||
{
|
||||
var defaultLanguage = languages.Where(l => l.IsDefault).SingleOrDefault() ?? languages.First();
|
||||
|
||||
SetLocalizationCookie(defaultLanguage.Code);
|
||||
}
|
||||
else
|
||||
@ -74,10 +65,6 @@ namespace Oqtane.Pages
|
||||
SetLocalizationCookie(_localizationManager.GetDefaultCulture());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Message = $"No Matching Alias For Host Name {hostname}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user