improve performance of alias handling and allow aliases to be an unlimited number of subfolders in depth

This commit is contained in:
Shaun Walker
2020-05-05 09:15:36 -04:00
parent bf84f12471
commit a02cfea6c9
54 changed files with 320 additions and 586 deletions

View File

@ -15,7 +15,6 @@ namespace Oqtane.Repository
public TenantResolver(IHttpContextAccessor accessor, IAliasRepository aliasRepository, ITenantRepository tenantRepository, SiteState siteState)
{
int aliasId = -1;
string aliasName = "";
if (siteState != null && siteState.Alias != null)
{
@ -23,29 +22,14 @@ namespace Oqtane.Repository
_alias = siteState.Alias;
}
else
{
// get alias identifier based on request context
{
// get aliasid identifier based on request
if (accessor.HttpContext != null)
{
// check if an alias is passed as a querystring parameter ( for cross tenant access )
if (accessor.HttpContext.Request.Query.ContainsKey("aliasid"))
string[] segments = accessor.HttpContext.Request.Path.Value.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (segments.Length > 1 && segments[1] == "api" && segments[0] != "~")
{
aliasId = int.Parse(accessor.HttpContext.Request.Query["aliasid"]);
}
else // get the alias from the request url
{
aliasName = accessor.HttpContext.Request.Host.Value;
string path = accessor.HttpContext.Request.Path.Value;
string[] segments = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (segments.Length > 1 && segments[1] == "api" && segments[0] != "~")
{
aliasName += "/" + segments[0];
}
if (aliasName.EndsWith("/"))
{
aliasName = aliasName.Substring(0, aliasName.Length - 1);
}
aliasId = int.Parse(segments[0]);
}
}
@ -55,14 +39,11 @@ namespace Oqtane.Repository
{
_alias = aliases.FirstOrDefault(item => item.AliasId == aliasId);
}
else
{
_alias = aliases.FirstOrDefault(item => item.Name == aliasName || aliases.Count() == 1);
}
}
if (_alias != null)
{
// get the tenant
IEnumerable<Tenant> tenants = tenantRepository.GetTenants(); // cached
_tenant = tenants.FirstOrDefault(item => item.TenantId == _alias.TenantId);
}