Skip to content

Commit

Permalink
Fixed Canonical and None mapping redirects (#3396)
Browse files Browse the repository at this point in the history
  • Loading branch information
daguiler authored and valadas committed Dec 10, 2019
1 parent 20c7df1 commit 46c17ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions DNN Platform/Library/Entities/Portals/PortalAliasExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ public static PortalAliasInfo GetAliasByPortalIdAndSettings(this IEnumerable<Por
{
var aliasList = aliases.ToList();

var defaultAlias = aliasList.ToList().Where(a => a.PortalID == portalId)
.OrderByDescending(a => a.IsPrimary)
.FirstOrDefault();

//First check if our current alias is already a perfect match.
PortalAliasInfo foundAlias = null;
if (result != null && !string.IsNullOrEmpty(result.HttpAlias))
Expand All @@ -107,15 +103,13 @@ public static PortalAliasInfo GetAliasByPortalIdAndSettings(this IEnumerable<Por
foundAlias = aliasList.FirstOrDefault(a => a.BrowserType == browserType &&
(String.Compare(a.CultureCode, cultureCode,
StringComparison.OrdinalIgnoreCase) == 0)
&& a.IsPrimary
&& a.PortalID == portalId
&& a.HTTPAlias == result.HttpAlias);
if (foundAlias == null) //let us try again using Startswith() to find matching Hosts
{
foundAlias = aliasList.FirstOrDefault(a => a.BrowserType == browserType &&
(String.Compare(a.CultureCode, cultureCode,
StringComparison.OrdinalIgnoreCase) == 0)
&& a.IsPrimary
&& a.PortalID == portalId
&& a.HTTPAlias.StartsWith(result.HttpAlias.Split('/')[0]));
}
Expand Down Expand Up @@ -164,10 +158,15 @@ public static PortalAliasInfo GetAliasByPortalIdAndSettings(this IEnumerable<Por
}
else
{
// if we didn't find a specific match, return the default, which is the closest match
var defaultAlias = aliasList
.Where(a => a.PortalID == portalId)
.OrderByDescending(a => a.IsPrimary)
.FirstOrDefault();

foundAlias = defaultAlias;
}

//if we didn't find a specific match, return the default, which is the closest match
return foundAlias;
}

Expand Down
4 changes: 3 additions & 1 deletion DNN Platform/Library/Entities/Urls/AdvancedUrlRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,9 @@ protected bool IsPortalAliasIncorrect(HttpContext context,
//var cpa = portalAliases.GetAliasByPortalIdAndSettings(result);
string url = requestUri.ToString();
RewriteController.CheckLanguageMatch(ref url, result);
var cpa = portalAliases.GetAliasByPortalIdAndSettings(result.PortalId, result, result.CultureCode, result.BrowserType);
var cpa = portalAliases
.Where(a => a.IsPrimary || result.PortalAliasMapping != PortalSettings.PortalAliasMapping.Redirect)
.GetAliasByPortalIdAndSettings(result.PortalId, result, result.CultureCode, result.BrowserType);

if (cpa != null)
{
Expand Down

0 comments on commit 46c17ff

Please sign in to comment.