コード例 #1
0
        private void ExecuteTestForTab(string test, TabInfo tab, FriendlyUrlSettings settings, Dictionary <string, string> testFields)
        {
            var    httpAlias    = testFields["Alias"];
            var    defaultAlias = testFields.GetValue("DefaultAlias", String.Empty);
            var    tabName      = testFields["Page Name"];
            var    scheme       = testFields["Scheme"];
            var    parameters   = testFields["Params"];
            var    result       = testFields["Expected Url"];
            var    customPage   = testFields.GetValue("Custom Page Name", _defaultPage);
            string vanityUrl    = testFields.GetValue("VanityUrl", String.Empty);

            var httpAliasFull  = scheme + httpAlias + "/";
            var expectedResult = result.Replace("{alias}", httpAlias)
                                 .Replace("{usealias}", defaultAlias)
                                 .Replace("{tabName}", tabName)
                                 .Replace("{tabId}", tab.TabID.ToString())
                                 .Replace("{vanityUrl}", vanityUrl)
                                 .Replace("{defaultPage}", _defaultPage);


            if (!String.IsNullOrEmpty(parameters) && !parameters.StartsWith("&"))
            {
                parameters = "&" + parameters;
            }

            var userName = testFields.GetValue("UserName", String.Empty);

            if (!String.IsNullOrEmpty(userName))
            {
                var user = UserController.GetUserByName(PortalId, userName);
                if (user != null)
                {
                    expectedResult = expectedResult.Replace("{userId}", user.UserID.ToString());
                    parameters     = parameters.Replace("{userId}", user.UserID.ToString());
                }
            }


            var    baseUrl = httpAliasFull + "Default.aspx?TabId=" + tab.TabID + parameters;
            string testUrl;

            if (test == "Base")
            {
                testUrl = AdvancedFriendlyUrlProvider.BaseFriendlyUrl(tab,
                                                                      baseUrl,
                                                                      customPage,
                                                                      httpAlias,
                                                                      settings);
            }
            else
            {
                testUrl = AdvancedFriendlyUrlProvider.ImprovedFriendlyUrl(tab,
                                                                          baseUrl,
                                                                          customPage,
                                                                          httpAlias,
                                                                          true,
                                                                          settings,
                                                                          Guid.Empty);
            }

            Assert.IsTrue(expectedResult.Equals(testUrl, StringComparison.InvariantCultureIgnoreCase));
        }
コード例 #2
0
        /// <summary>
        /// For the supplied options, return a tab path for the specified tab.
        /// </summary>
        /// <param name="tab">TabInfo object of selected tab.</param>
        /// <param name="settings">FriendlyUrlSettings.</param>
        /// <param name="options"></param>
        /// <param name="ignoreCustomRedirects">Whether to add in the customised Tab redirects or not.</param>
        /// <param name="homePageSiteRoot"></param>
        /// <param name="isHomeTab"></param>
        /// <param name="cultureCode"></param>
        /// <param name="isDefaultCultureCode"></param>
        /// <param name="hasPath"></param>
        /// <param name="dropLangParms"></param>
        /// <param name="customHttpAlias"></param>
        /// <param name="isCustomPath"></param>
        /// <param name="parentTraceId"></param>
        /// <remarks>751 : include isDefaultCultureCode flag to determine when using the portal default language
        /// 770 : include custom http alias output for when the Url uses a specific alias due to custom Url rules
        ///  : include new out parameter 'isCustomPath' to return whether the Url was generated from Url-Master custom url.
        /// </remarks>
        /// <returns>The tab path as specified.</returns>
        internal static string GetTabPath(
            TabInfo tab,
            FriendlyUrlSettings settings,
            FriendlyUrlOptions options,
            bool ignoreCustomRedirects,
            bool homePageSiteRoot,
            bool isHomeTab,
            string cultureCode,
            bool isDefaultCultureCode,
            bool hasPath,
            out bool dropLangParms,
            out string customHttpAlias,
            out bool isCustomPath,
            Guid parentTraceId)
        {
            string newTabPath;

            dropLangParms   = false;
            customHttpAlias = null;
            isCustomPath    = false;
            if (homePageSiteRoot && isHomeTab && !hasPath)

            // && !isDefaultCultureCode - not working for non-language specifc custom root urls
            {
                newTabPath = "/"; // site root for home page
            }
            else
            {
                // build the tab path and check for space replacement
                string baseTabPath = TabIndexController.GetTabPath(tab, options, parentTraceId);

                // this is the new tab path
                newTabPath = baseTabPath;

                // 871 : case insensitive compare for culture code, all lookups done on lower case
                string cultureCodeKey = string.Empty;
                if (cultureCode != null)
                {
                    cultureCodeKey = cultureCode.ToLowerInvariant();
                }

                bool checkForCustomHttpAlias = false;

                // get a custom tab name if redirects are being used
                SharedDictionary <string, string> customAliasForTabs = null;
                SharedDictionary <int, SharedDictionary <string, string> > urlDict;

                // 886 : don't fetch custom urls for host tabs (host tabs can't have redirects or custom Urls)
                if (tab.PortalID > -1)
                {
                    urlDict = CustomUrlDictController.FetchCustomUrlDictionary(tab.PortalID, false, false, settings, out customAliasForTabs, parentTraceId);
                }
                else
                {
                    urlDict = new SharedDictionary <int, SharedDictionary <string, string> >();

                    // create dummy dictionary for this tab
                }

                if (ignoreCustomRedirects == false)
                {
                    // if not ignoring the custom redirects, look for the Url of the page in this list
                    // this will be used as the page path if there is one.
                    using (urlDict.GetReadLock())
                    {
                        if (urlDict.ContainsKey(tab.TabID))
                        {
                            // we want the custom value
                            string customTabPath = null;
                            SharedDictionary <string, string> tabpaths = urlDict[tab.TabID];

                            using (tabpaths.GetReadLock())
                            {
                                if (tabpaths.ContainsKey(cultureCodeKey))
                                {
                                    customTabPath = tabpaths[cultureCodeKey];
                                    dropLangParms = true;

                                    // the url is based on a custom value which has embedded language parms, therefore don't need them in the url
                                }
                                else
                                {
                                    if (isDefaultCultureCode && tabpaths.ContainsKey(string.Empty))
                                    {
                                        customTabPath = tabpaths[string.Empty];

                                        // dropLangParms = true;//drop the language parms if they exist, because this is the default language
                                    }
                                }
                            }

                            if (customTabPath != null)
                            {
                                // 770 : pull out custom http alias if in string
                                int aliasSeparator = customTabPath.IndexOf("::", StringComparison.Ordinal);
                                if (aliasSeparator > 0)
                                {
                                    customHttpAlias = customTabPath.Substring(0, aliasSeparator);
                                    newTabPath      = customTabPath.Substring(aliasSeparator + 2);
                                }
                                else
                                {
                                    newTabPath = customTabPath;
                                }
                            }

                            if (newTabPath == string.Empty && hasPath)
                            {
                                // can't pass back a custom path which is blank if there are path segments to the requested final Url
                                newTabPath = baseTabPath; // revert back to the standard DNN page path
                            }
                            else
                            {
                                isCustomPath = true; // we are providing a custom Url
                            }
                        }
                        else
                        {
                            checkForCustomHttpAlias = true;
                        }
                    }
                }
                else
                {
                    checkForCustomHttpAlias = true;

                    // always want to check for custom alias, even when we don't want to see any custom redirects
                }

                // 770 : check for custom alias in these tabs
                if (checkForCustomHttpAlias && customAliasForTabs != null)
                {
                    string key = tab.TabID.ToString() + ":" + cultureCodeKey;
                    using (customAliasForTabs.GetReadLock())
                    {
                        if (customAliasForTabs.ContainsKey(key))
                        {
                            // this tab uses a custom alias
                            customHttpAlias = customAliasForTabs[key];
                            isCustomPath    = true; // using custom alias
                        }
                    }
                }

                if (!dropLangParms)
                {
                    string tabCultureCode = tab.CultureCode;
                    if (!string.IsNullOrEmpty(tabCultureCode))
                    {
                        dropLangParms = true;

                        // if the tab has a specified culture code, then drop the language parameters from the friendly Url
                    }
                }

                // make lower case if necessary
                newTabPath = AdvancedFriendlyUrlProvider.ForceLowerCaseIfAllowed(tab, newTabPath, settings);
            }

            return(newTabPath);
        }
コード例 #3
0
        private static bool ValidateUrl(string url, int validateUrlForTabId, PortalSettings settings)
        {
            // Try and get a user by the url
            var  user     = UserController.GetUserByVanityUrl(settings.PortalId, url);
            bool isUnique = user == null;

            if (isUnique)
            {
                // Try and get a tab by the url
                int tabId = TabController.GetTabByTabPath(settings.PortalId, "//" + url, settings.CultureCode);
                isUnique = tabId == -1 || tabId == validateUrlForTabId;
            }

            // check whether have a tab which use the url.
            if (isUnique)
            {
                var friendlyUrlSettings = GetCurrentSettings(settings.PortalId);
                var tabs = TabController.Instance.GetTabsByPortal(settings.PortalId).AsList();

                // DNN-6492: if content localize enabled, only check tab names in current culture.
                if (settings.ContentLocalizationEnabled)
                {
                    tabs = tabs.Where(t => t.CultureCode == settings.CultureCode).ToList();
                }

                foreach (TabInfo tab in tabs)
                {
                    if (tab.TabID == validateUrlForTabId)
                    {
                        continue;
                    }

                    if (tab.TabUrls.Count == 0)
                    {
                        var baseUrl = Globals.AddHTTP(settings.PortalAlias.HTTPAlias) + "/Default.aspx?TabId=" + tab.TabID;
                        var path    = AdvancedFriendlyUrlProvider.ImprovedFriendlyUrl(
                            tab,
                            baseUrl,
                            Globals.glbDefaultPage,
                            settings.PortalAlias.HTTPAlias,
                            false,
                            friendlyUrlSettings,
                            Guid.Empty);

                        var tabUrl = path.Replace(Globals.AddHTTP(settings.PortalAlias.HTTPAlias), string.Empty);

                        if (tabUrl.Equals("/" + url, StringComparison.InvariantCultureIgnoreCase))
                        {
                            isUnique = false;
                            break;
                        }
                    }
                    else if (tab.TabUrls.Any(u => u.Url.Equals("/" + url, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        isUnique = false;
                        break;
                    }
                }
            }

            return(isUnique);
        }
コード例 #4
0
        public void SaveTabUrl(TabInfo tab, PageSettings pageSettings)
        {
            if (!pageSettings.CustomUrlEnabled)
            {
                return;
            }

            if (tab.IsSuperTab)
            {
                return;
            }

            var url    = pageSettings.Url;
            var tabUrl = tab.TabUrls.SingleOrDefault(t => t.IsSystem &&
                                                     t.HttpStatus == "200" &&
                                                     t.SeqNum == 0);

            var portalSettings = PortalController.Instance.GetCurrentPortalSettings();

            if (!String.IsNullOrEmpty(url) && url != "/")
            {
                url = CleanTabUrl(url);

                string currentUrl          = String.Empty;
                var    friendlyUrlSettings = new FriendlyUrlSettings(portalSettings.PortalId);
                if (tab.TabID > -1)
                {
                    var baseUrl = Globals.AddHTTP(portalSettings.PortalAlias.HTTPAlias) + "/Default.aspx?TabId=" + tab.TabID;
                    var path    = AdvancedFriendlyUrlProvider.ImprovedFriendlyUrl(tab,
                                                                                  baseUrl,
                                                                                  Globals.glbDefaultPage,
                                                                                  portalSettings.PortalAlias.HTTPAlias,
                                                                                  false,
                                                                                  friendlyUrlSettings,
                                                                                  Guid.Empty);

                    currentUrl = path.Replace(Globals.AddHTTP(portalSettings.PortalAlias.HTTPAlias), "");
                }

                if (url == currentUrl)
                {
                    return;
                }

                if (tabUrl == null)
                {
                    //Add new custom url
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = 0,
                        PortalAliasId    = -1,
                        PortalAliasUsage = PortalAliasUsageType.Default,
                        QueryString      = String.Empty,
                        Url         = url,
                        HttpStatus  = "200",
                        CultureCode = String.Empty,
                        IsSystem    = true
                    };
                    //Save url
                    _tabController.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
                else
                {
                    //Change the original 200 url to a redirect
                    tabUrl.HttpStatus = "301";
                    tabUrl.SeqNum     = tab.TabUrls.Max(t => t.SeqNum) + 1;
                    _tabController.SaveTabUrl(tabUrl, portalSettings.PortalId, true);

                    //Add new custom url
                    tabUrl.Url        = url;
                    tabUrl.HttpStatus = "200";
                    tabUrl.SeqNum     = 0;
                    _tabController.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }


                //Delete any redirects to the same url
                foreach (var redirecturl in _tabController.GetTabUrls(tab.TabID, tab.PortalID))
                {
                    if (redirecturl.Url == url && redirecturl.HttpStatus != "200")
                    {
                        _tabController.DeleteTabUrl(redirecturl, tab.PortalID, true);
                    }
                }
            }
            else
            {
                if (url == "/" && tabUrl != null)
                {
                    _tabController.DeleteTabUrl(tabUrl, portalSettings.PortalId, true);
                }
            }
        }
コード例 #5
0
        private IEnumerable <Url> GetSortedUrls(TabInfo tab, int portalId, Lazy <Dictionary <string, Locale> > locales, int sortColumn, bool sortOrder, bool isSystem)
        {
            var friendlyUrlSettings = new FriendlyUrlSettings(tab.PortalID);
            var tabs = new List <Url>();

            if (isSystem)
            {
                //Add generated urls
                foreach (var alias in PortalAliasController.Instance.GetPortalAliasesByPortalId(portalId))
                {
                    var urlLocale = locales.Value.Values.FirstOrDefault(local => local.Code == alias.CultureCode);

                    /*var isRedirected = tab.TabUrls.Any(u => u.HttpStatus == "200"
                     *                                      && u.CultureCode == ((urlLocale != null) ? urlLocale.Code : String.Empty))
                     || alias.PortalAliasID != PrimaryAliasId;*/

                    bool isRedirected    = false;
                    var  isCustom200Urls = tab.TabUrls.Any(u => u.HttpStatus == "200");//are there any custom Urls for this tab?
                    var  baseUrl         = Globals.AddHTTP(alias.HTTPAlias) + "/Default.aspx?TabId=" + tab.TabID;
                    if (urlLocale != null)
                    {
                        baseUrl += "&language=" + urlLocale.Code;
                    }
                    string customPath = null;
                    if (isCustom200Urls)
                    {
                        //get the friendlyUrl, including custom Urls
                        customPath = AdvancedFriendlyUrlProvider.ImprovedFriendlyUrl(tab,
                                                                                     baseUrl,
                                                                                     Globals.glbDefaultPage,
                                                                                     alias.HTTPAlias,
                                                                                     false,
                                                                                     friendlyUrlSettings,
                                                                                     Guid.Empty);

                        customPath = customPath.Replace(Globals.AddHTTP(alias.HTTPAlias), "");
                    }
                    //get the friendlyUrl and ignore and custom Urls
                    var path = AdvancedFriendlyUrlProvider.ImprovedFriendlyUrl(tab,
                                                                               baseUrl,
                                                                               Globals.glbDefaultPage,
                                                                               alias.HTTPAlias,
                                                                               true,
                                                                               friendlyUrlSettings,
                                                                               Guid.Empty);

                    path = path.Replace(Globals.AddHTTP(alias.HTTPAlias), "");
                    int status = 200;
                    if (customPath != null && (string.Compare(customPath, path, StringComparison.InvariantCultureIgnoreCase) != 0))
                    {
                        //difference in custom/standard URL, so standard is 301
                        status       = 301;
                        isRedirected = true;
                    }
                    //AddUrlToList(tabs, -1, alias, urlLocale, path, String.Empty, (isRedirected) ? 301 : 200);
                    //27139 : only show primary aliases in the tab grid (gets too confusing otherwise)
                    if (alias.IsPrimary) //alias was provided to FriendlyUrlCall, so will always get the correct canonical Url back
                    {
                        AddUrlToList(tabs, portalId, -1, alias, urlLocale, path, String.Empty, status, isSystem, friendlyUrlSettings, null);
                    }

                    //Add url with diacritics
                    isRedirected = friendlyUrlSettings.RedirectUnfriendly;
                    bool   replacedDiacritic;
                    string asciiTabPath = TabPathHelper.ReplaceDiacritics(tab.TabPath, out replacedDiacritic).Replace("//", "/");
                    if (replacedDiacritic)
                    {
                        if (friendlyUrlSettings.AutoAsciiConvert)
                        {
                            if (friendlyUrlSettings.ReplaceSpaceWith != FriendlyUrlSettings.ReplaceSpaceWithNothing)
                            {
                                path = path.Replace(friendlyUrlSettings.ReplaceSpaceWith, String.Empty);
                            }
                            path = path.Replace(asciiTabPath, tab.TabPath.Replace("//", "/"));
                            AddUrlToList(tabs, portalId, -1, alias, urlLocale, path, String.Empty, (isRedirected) ? 301 : 200, isSystem, friendlyUrlSettings, null);
                        }
                    }
                    else
                    {
                        //Add url with space
                        if (tab.TabName.Contains(" ") && friendlyUrlSettings.ReplaceSpaceWith != FriendlyUrlSettings.ReplaceSpaceWithNothing)
                        {
                            path = path.Replace(friendlyUrlSettings.ReplaceSpaceWith, String.Empty);
                            if (customPath != null && string.Compare(customPath, path, StringComparison.InvariantCultureIgnoreCase) != 0)
                            {
                                AddUrlToList(tabs, portalId, -1, alias, urlLocale, path, String.Empty, (isRedirected) ? 301 : 200, isSystem, friendlyUrlSettings, null);
                            }
                        }
                    }
                }
            }

            foreach (var url in tab.TabUrls.Where(u => u.IsSystem == isSystem).OrderBy(u => u.SeqNum))
            {
                int statusCode;
                int.TryParse(url.HttpStatus, out statusCode);

                //27133 : Only show a custom URL
                if (url.PortalAliasUsage == PortalAliasUsageType.Default)
                {
                    var aliases = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalId);
                    var alias   = aliases.FirstOrDefault(primary => primary.IsPrimary == true);
                    if (alias == null)
                    {
                        //if no primary alias just get first in list, need to use something
                        alias = aliases.FirstOrDefault(a => a.PortalID == portalId);
                    }
                    if (alias != null)
                    {
                        var urlLocale = locales.Value.Values.FirstOrDefault(local => local.Code == alias.CultureCode);
                        AddUrlToList(tabs, portalId, url.SeqNum, alias, urlLocale, url.Url, url.QueryString, statusCode, isSystem, friendlyUrlSettings, url.LastModifiedByUserId);
                    }
                }
                else
                {
                    var urlLocale = locales.Value.Values.FirstOrDefault(local => local.Code == url.CultureCode);
                    var alias     = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalId)
                                    .SingleOrDefault(p => p.PortalAliasID == url.PortalAliasId);

                    AddUrlToList(tabs, portalId, url.SeqNum, alias, urlLocale, url.Url, url.QueryString, statusCode, isSystem, friendlyUrlSettings, url.LastModifiedByUserId);
                }
            }

            var pairComparer = new KeyValuePairComparer();

            switch ((SortingFields)sortColumn)
            {
            case SortingFields.Url:
            case SortingFields.None:
                return(sortOrder ?
                       tabs.OrderBy(url => url.SiteAlias, pairComparer).ThenBy(url => url.Path) :
                       tabs.OrderByDescending(url => url.SiteAlias, pairComparer).ThenByDescending(url => url.Path));

            case SortingFields.Locale:
                return(sortOrder ?
                       tabs.OrderBy(url => url.Locale, pairComparer) :
                       tabs.OrderByDescending(url => url.Locale, pairComparer));

            case SortingFields.Status:
                return(sortOrder ?
                       tabs.OrderBy(url => url.StatusCode, pairComparer) :
                       tabs.OrderByDescending(url => url.StatusCode, pairComparer));

            default:
                return(sortOrder ?
                       tabs.OrderBy(url => url.SiteAlias, pairComparer).ThenBy(url => url.Path) :
                       tabs.OrderByDescending(url => url.SiteAlias, pairComparer).ThenByDescending(url => url.Path));
            }
        }
コード例 #6
0
        internal static bool CheckForParameterRedirect(
            Uri requestUri,
            ref UrlAction result,
            NameValueCollection queryStringCol,
            FriendlyUrlSettings settings)
        {
            // check for parameter replaced works by inspecting the parameters on a rewritten request, comparing
            // them agains the list of regex expressions on the friendlyurls.config file, and redirecting to the same page
            // but with new parameters, if there was a match
            bool redirect = false;

            // get the redirect actions for this portal
            var messages = new List <string>();
            Dictionary <int, List <ParameterRedirectAction> > redirectActions = CacheController.GetParameterRedirects(settings, result.PortalId, ref messages);

            if (redirectActions != null && redirectActions.Count > 0)
            {
                try
                {
                    string rewrittenUrl = result.RewritePath ?? result.RawUrl;

                    List <ParameterRedirectAction> parmRedirects = null;

                    // find the matching redirects for the tabid
                    int tabId = result.TabId;
                    if (tabId > -1)
                    {
                        if (redirectActions.ContainsKey(tabId))
                        {
                            // find the right set of replaced actions for this tab
                            parmRedirects = redirectActions[tabId];
                        }
                    }

                    // check for 'all tabs' redirections
                    if (redirectActions.ContainsKey(-1)) // -1 means 'all tabs' - rewriting across all tabs
                    {
                        // initialise to empty collection if there are no specific tab redirects
                        if (parmRedirects == null)
                        {
                            parmRedirects = new List <ParameterRedirectAction>();
                        }

                        // add in the all redirects
                        List <ParameterRedirectAction> allRedirects = redirectActions[-1];
                        parmRedirects.AddRange(allRedirects); // add the 'all' range to the tab range
                        tabId = result.TabId;
                    }

                    if (redirectActions.ContainsKey(-2) && result.OriginalPath.ToLowerInvariant().Contains("default.aspx"))
                    {
                        // for the default.aspx page
                        if (parmRedirects == null)
                        {
                            parmRedirects = new List <ParameterRedirectAction>();
                        }

                        List <ParameterRedirectAction> defaultRedirects = redirectActions[-2];
                        parmRedirects.AddRange(defaultRedirects); // add the default.aspx redirects to the list
                        tabId = result.TabId;
                    }

                    // 726 : allow for site-root redirects, ie redirects where no page match
                    if (redirectActions.ContainsKey(-3))
                    {
                        // request is for site root
                        if (parmRedirects == null)
                        {
                            parmRedirects = new List <ParameterRedirectAction>();
                        }

                        List <ParameterRedirectAction> siteRootRedirects = redirectActions[-3];
                        parmRedirects.AddRange(siteRootRedirects); // add the site root redirects to the collection
                    }

                    // OK what we have now is a list of redirects for the currently requested tab (either because it was specified by tab id,
                    // or because there is a replaced for 'all tabs'
                    if (parmRedirects != null && parmRedirects.Count > 0 && rewrittenUrl != null)
                    {
                        foreach (ParameterRedirectAction parmRedirect in parmRedirects)
                        {
                            // regex test each replaced to see if there is a match between the parameter string
                            // and the parmRedirect
                            string compareWith   = rewrittenUrl;
                            var    redirectRegex = RegexUtils.GetCachedRegex(
                                parmRedirect.LookFor,
                                RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                            Match regexMatch    = redirectRegex.Match(compareWith);
                            bool  success       = regexMatch.Success;
                            bool  siteRootTried = false;

                            // if no match, but there is a site root redirect to try
                            if (!success && parmRedirect.TabId == -3)
                            {
                                siteRootTried = true;
                                compareWith   = result.OriginalPathNoAlias;
                                regexMatch    = redirectRegex.Match(compareWith);
                                success       = regexMatch.Success;
                            }

                            if (!success)
                            {
                                result.DebugMessages.Add(parmRedirect.Name + " redirect not matched (" + rewrittenUrl +
                                                         ")");
                                if (siteRootTried)
                                {
                                    result.DebugMessages.Add(parmRedirect.Name + " redirect not matched [site root] (" +
                                                             result.OriginalPathNoAlias + ")");
                                }
                            }
                            else
                            {
                                // success! there was a match in the parameters
                                string parms = redirectRegex.Replace(compareWith, parmRedirect.RedirectTo);
                                if (siteRootTried)
                                {
                                    result.DebugMessages.Add(parmRedirect.Name + " redirect matched [site root] with (" +
                                                             result.OriginalPathNoAlias + "), replaced with " + parms);
                                }
                                else
                                {
                                    result.DebugMessages.Add(parmRedirect.Name + " redirect matched with (" +
                                                             compareWith + "), replaced with " + parms);
                                }

                                string finalUrl = string.Empty;

                                // now we need to generate the friendly Url

                                // first check to see if the parameter replacement string has a destination tabid specified
                                if (parms.ToLowerInvariant().Contains("tabid/"))
                                {
                                    // if so, using a feature whereby the dest tabid can be changed within the parameters, which will
                                    // redirect the page as well as redirecting the parameter values
                                    string[] parmParts = parms.Split('/');
                                    bool     tabIdNext = false;
                                    foreach (string parmPart in parmParts)
                                    {
                                        if (tabIdNext)
                                        {
                                            // changes the tabid of page, effects a page redirect along with a parameter redirect
                                            int.TryParse(parmPart, out tabId);
                                            parms = parms.Replace("tabid/" + tabId.ToString(), string.Empty);

                                            // remove the tabid/xx from the path
                                            break; // that's it, we're finished
                                        }

                                        if (parmPart.Equals("tabid", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            tabIdNext = true;
                                        }
                                    }
                                }
                                else if (tabId == -1)
                                {
                                    // find the home tabid for this portal
                                    // 735 : switch to custom method for getting portal
                                    PortalInfo portal = CacheController.GetPortal(result.PortalId, true);
                                    tabId = portal.HomeTabId;
                                }

                                if (parmRedirect.ChangeToSiteRoot)
                                {
                                    // when change to siteroot requested, new path goes directly off the portal alias
                                    // so set the finalUrl as the poratl alias
                                    finalUrl = result.Scheme + result.HttpAlias + "/";
                                }
                                else
                                {
                                    // if the tabid has been supplied, do a friendly url provider lookup to get the correct format for the tab url
                                    if (tabId > -1)
                                    {
                                        TabInfo tab = TabController.Instance.GetTab(tabId, result.PortalId, false);
                                        if (tab != null)
                                        {
                                            string path = Globals.glbDefaultPage + TabIndexController.CreateRewritePath(tab.TabID, string.Empty);
                                            string friendlyUrlNoParms = AdvancedFriendlyUrlProvider.ImprovedFriendlyUrl(
                                                tab,
                                                path,
                                                Globals.glbDefaultPage,
                                                result.HttpAlias,
                                                false,
                                                settings,
                                                Guid.Empty);
                                            if (friendlyUrlNoParms.EndsWith("/") == false)
                                            {
                                                friendlyUrlNoParms += "/";
                                            }

                                            finalUrl = friendlyUrlNoParms;
                                        }

                                        if (tab == null)
                                        {
                                            result.DebugMessages.Add(parmRedirect.Name +
                                                                     " tabId in redirect rule (tabId:" +
                                                                     tabId.ToString() + ", portalId:" +
                                                                     result.PortalId.ToString() +
                                                                     " ), tab was not found");
                                        }
                                        else
                                        {
                                            result.DebugMessages.Add(parmRedirect.Name +
                                                                     " tabId in redirect rule (tabId:" +
                                                                     tabId.ToString() + ", portalId:" +
                                                                     result.PortalId.ToString() + " ), tab found : " +
                                                                     tab.TabName);
                                        }
                                    }
                                }

                                if (parms.StartsWith("//"))
                                {
                                    parms = parms.Substring(2);
                                }

                                if (parms.StartsWith("/"))
                                {
                                    parms = parms.Substring(1);
                                }

                                if (settings.PageExtensionUsageType != PageExtensionUsageType.Never)
                                {
                                    if (parms.EndsWith("/"))
                                    {
                                        parms = parms.TrimEnd('/');
                                    }

                                    if (parms.Length > 0)
                                    {
                                        // we are adding more parms onto the end, so remove the page extension
                                        // from the parameter list
                                        // 946 : exception when settings.PageExtension value is empty
                                        parms += settings.PageExtension;

                                        // 816: if page extension is /, then don't do this
                                        if (settings.PageExtension != "/" &&
                                            string.IsNullOrEmpty(settings.PageExtension) == false)
                                        {
                                            finalUrl = finalUrl.Replace(settings.PageExtension, string.Empty);
                                        }
                                    }
                                    else
                                    {
                                        // we are removing all the parms altogether, so
                                        // the url needs to end in the page extension only
                                        // 816: if page extension is /, then don't do this
                                        if (settings.PageExtension != "/" &&
                                            string.IsNullOrEmpty(settings.PageExtension) == false)
                                        {
                                            finalUrl = finalUrl.Replace(
                                                settings.PageExtension + "/",
                                                settings.PageExtension);
                                        }
                                    }
                                }

                                // put the replaced parms back on the end
                                finalUrl += parms;

                                // set the final url
                                result.FinalUrl = finalUrl;
                                result.Reason   = RedirectReason.Custom_Redirect;
                                switch (parmRedirect.Action)
                                {
                                case "301":
                                    result.Action = ActionType.Redirect301;
                                    break;

                                case "302":
                                    result.Action = ActionType.Redirect302;
                                    break;

                                case "404":
                                    result.Action = ActionType.Output404;
                                    break;
                                }

                                redirect = true;
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Services.Exceptions.Exceptions.LogException(ex);
                    messages.Add("Exception: " + ex.Message + "\n" + ex.StackTrace);
                }
                finally
                {
                    if (messages.Count > 0)
                    {
                        result.DebugMessages.AddRange(messages);
                    }
                }
            }

            return(redirect);
        }