Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not redirecting to primary alias when tab-specific alias exists #3832

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion DNN Platform/Library/Entities/Urls/AdvancedUrlRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,22 @@ private void ProcessRequest(HttpContext context,
}
}

// now we may know the TabId. If the current alias is not the same as the primary alias,
// we should check if the current alias is indeed a valid custom alias for the current tab.
if (result.TabId > 0 && result.HttpAlias != result.PrimaryAlias.HTTPAlias && !CheckIfAliasIsCurrentTabCustomTabAlias(ref result, settings))
{
//it was an incorrect alias
//try and redirect the alias if the settings allow it
if( RedirectPortalAlias(result.PrimaryAlias.HTTPAlias, ref result, settings))
{
//not correct alias for tab : will be redirected
//perform a 301 redirect if one has already been found
response.AppendHeader("X-Redirect-Reason", result.Reason.ToString().Replace("_", " ") + " Requested");
response.RedirectPermanent(result.FinalUrl, false);
finished = true;
}
}

if (!finished && result.DoRewrite)
{
//check the identified portal alias details for any extra rewrite information required
Expand Down Expand Up @@ -1813,6 +1829,39 @@ private static bool CheckIfAliasIsCustomTabAlias(ref UrlAction result, string ht
return isACustomTabAlias;
}
/// <summary>
/// Checks to see whether the specified alias is a customTabAlias for the TabId in result
/// </summary>
/// <param name="result"></param>
/// <param name="httpAlias"></param>
/// <param name="settings"></param>
/// <returns></returns>
private static bool CheckIfAliasIsCurrentTabCustomTabAlias(ref UrlAction result, FriendlyUrlSettings settings)
{
var customAliasesForTab = TabController.Instance.GetCustomAliases(result.TabId, result.PortalId);
bool isCurrentTabCustomTabAlias = false;
if (customAliasesForTab != null && customAliasesForTab.Count > 0)
{
//see if we have a customAlias for the current CultureCode
if (customAliasesForTab.ContainsKey(result.CultureCode))
{
//if it is for the current culture, we need to know if it's a primary alias
var tabPortalAlias = PortalAliasController.Instance.GetPortalAlias(customAliasesForTab[result.CultureCode]);
if (tabPortalAlias != null && !tabPortalAlias.IsPrimary)
{
// it's not a primary alias, so must be a custom tab alias
isCurrentTabCustomTabAlias = true;
}
}
}
// if it's not a custom alias for the current tab, we'll need to change the result
if (!isCurrentTabCustomTabAlias)
{
result.Action = ActionType.Redirect301;
result.Reason = RedirectReason.Wrong_Portal_Alias;
}
return isCurrentTabCustomTabAlias;
}
/// <summary>
/// Configures the result object to set the correct Alias redirect
/// parameters and destination URL
/// </summary>
Expand All @@ -1838,8 +1887,15 @@ private static bool ConfigurePortalAliasRedirect(ref UrlAction result,
if (ignoreCustomAliasTabs == false) //check out custom alias tabs collection
{
//if an alias is a custom tab alias for a specific tab, then don't redirect
if (CheckIfAliasIsCustomTabAlias(ref result, wrongAlias, settings))
// if we have the TabId, we'll need to check if the alias is valid for the current tab
if (result.TabId > 0 && CheckIfAliasIsCurrentTabCustomTabAlias(ref result, settings))
{
doRedirect = false;
}
else if (result.TabId < 0 && CheckIfAliasIsCustomTabAlias(ref result, wrongAlias, settings))
{
doRedirect = false;
}
else
{
doRedirect = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,43 @@ CREATE NONCLUSTERED INDEX [IX_{objectQualifier}Users_PasswordResetToken] ON {dat
[PasswordResetToken] ASC
)
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}GetTabCustomAliases') AND type in (N'P', N'PC'))
DROP PROCEDURE {databaseOwner}{objectQualifier}GetTabCustomAliases
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE {databaseOwner}{objectQualifier}GetTabCustomAliases
(
@PortalID int
)
AS
SELECT
t.TabId,
Coalesce(trp.CultureCode, '') as CultureCode,
pa.HttpAlias
FROM {databaseOwner}{objectQualifier}Tabs t
INNER JOIN {databaseOwner}{objectQualifier}TabUrls trp ON trp.TabId = t.ParentId
INNER JOIN {databaseOwner}{objectQualifier}PortalAlias pa ON trp.PortalAliasId = pa.PortalAliasId
WHERE trp.PortalAliasUsage = 1 /* child tabs inherit */
AND (@portalId = t.PortalId OR @portalId = -1)
AND NOT EXISTS (SELECT tr2.TabId
FROM {databaseOwner}{objectQualifier}TabUrls tr2
WHERE tr2.TabId = t.TabId
AND tr2.CultureCode = trp.CultureCode
)
UNION
SELECT
t.TabId,
Coalesce(trp.CultureCode, '') as CultureCode,
pa.HttpAlias
FROM {databaseOwner}{objectQualifier}Tabs t
INNER JOIN {databaseOwner}{objectQualifier}TabUrls trp ON trp.TabId = t.Tabid
INNER JOIN {databaseOwner}{objectQualifier}PortalAlias pa ON trp.PortalAliasId = pa.PortalAliasId
WHERE (@portalId = t.PortalId OR @portalId = -1)
AND t.CultureCode IS NULL OR t.CultureCode = trp.CultureCode
GO