コード例 #1
0
 /// <summary>
 /// Generates a new friendly Url based on the parameters supplied
 /// </summary>
 /// <param name="tab">The current Tab the Friendly Url is for</param>
 /// <param name="friendlyUrlPath">The current friendly Url Path (minus alias) as generated by the Advanced Friendly Url provider</param>
 /// <param name="options">The current friendly Url options that apply to the current portal, as configured within the Extension Url Provider settings.  These include space replacement values and other settings which should be incorporated into the Friendly Url generation.</param>
 /// <param name="endingPageName">The 'pageName' value that comes from the FriendlyUrl API of Hotcakes Commerce.  Normally this is the 'default.aspx' value (DotNetNuke.Common.Globals.glbDefaultPage).  A value of 'default.aspx' is discarded. However, it may be a different value for other modules and if not default.aspx will be appended to the end of the Url.
 /// This is a ref parameter, so it can either be left as-is, or changed to default.aspx or "" if no specific value is required.</param>
 /// <param name="useDnnPagePath">Output parameter, must be set by module Friendly Url Provider.  If true, the /pagename/ part of the Url will be removed, and the Url path will be relative from the site root (example.com/custom-module-path instead of example.com/pagename/custom-module-path)</param>
 /// <param name="messages">A list of information messages used for both debug output and UI information.  Add any informational message to this collection if desired.</param>
 /// <remarks>Note using 'useDnnPagePath' = true requires having a specific tab returned from the TransformFriendlyUrlToQueryString below.  Usage of the 'useDnnPagePath' implies the TransformFriendlyUrlToQueryString method returns a ?tabid=xx value in the querystring.
 /// It also means the provider level property 'AlwaysUsesDnnPagePath' must return 'false'</remarks>
 /// <returns>Friendly Url for specified values.  Return friendlyUrlPath if no change is made.</returns>
 public abstract string ChangeFriendlyUrl(TabInfo tab,
                                          string friendlyUrlPath,
                                          FriendlyUrlOptions options,
                                          string cultureCode,
                                          ref string endingPageName,
                                          out bool useDnnPagePath,
                                          ref List <string> messages);
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tabId"></param>
 /// <param name="portalid"></param>
 /// <param name="requestUri"></param>
 /// <param name="queryStringCol"></param>
 /// <param name="options"></param>
 /// <param name="messages"></param>
 /// <returns></returns>
 public abstract bool CheckForRedirect(int tabId,
                                       int portalid,
                                       string httpAlias,
                                       Uri requestUri,
                                       NameValueCollection queryStringCol,
                                       FriendlyUrlOptions options,
                                       out string redirectLocation,
                                       ref List <string> messages);
コード例 #3
0
 /// <summary>
 /// Transforms a friendly Url into a querystring.  Used as input into the rewriting process, after the Url Rewriting process has identified the correct Hotcakes Commerce Page.
 /// </summary>
 /// <param name="urlParms">string array of the friendly Url Path elements, separated by /</param>
 /// <param name="tabId">TabId of page the Friendly Url </param>
 /// <param name="portalId">PortalId of the Friendly Url</param>
 /// <remarks>This method will be only called if there is no match between the Page Index entries this Provider supplies via the 'CreatePageIndex' method.  This method is called
 /// when a Hotcakes Commerce page match is found in the requested path, and there are other parameters behind the page path. You should only return a TabId in the querystring, when the ChangeFriendlyUrl function is returning 'true' for the output value of 'useDnnPagePath'.</remarks>
 /// <example>
 /// Given a Url of example.com/pagename/key/value - this method will be called with key,value in the urlParms array with a page match on 'pagename'.  The method should return 'key=value'.
 /// Or, if given a Url of example.com/pagename/my-friendly-module-url, it should transform 'my-friendly-module-url' into whatever the module actually uses to build content.  This might mean returning 'article=2354' derived from doing a specific lookup on 'my-friendly-module-url'.
 /// Warning: It's unwise to do a specific database lookup for each call of this method.  This method needs to be high-performance so should use a stateless method (ie, regex parse) or, if looking up database values, cached hashtables or thread-safe dictionaries.
 /// </example>
 /// <returns>Querystring value in key=value format, which will be used as an input to the rewriting function.</returns>
 public abstract string TransformFriendlyUrlToQueryString(string[] urlParms,
                                                          int tabId, int portalId,
                                                          FriendlyUrlOptions options,
                                                          string cultureCode,
                                                          PortalAliasInfo portalAlias,
                                                          ref List <string> messages,
                                                          out int status,
                                                          out string location);
コード例 #4
0
        internal static bool CheckForRedirect(
            Uri requestUri,
            UrlAction result,
            NameValueCollection queryStringCol,
            FriendlyUrlSettings settings,
            out string location,
            ref List <string> messages,
            Guid parentTraceId)
        {
            bool redirected = false;

            location = string.Empty;
            ExtensionUrlProvider activeProvider = null;

            try
            {
                List <ExtensionUrlProvider> providersToCall = GetProvidersToCall(result.TabId, result.PortalId, settings,
                                                                                 parentTraceId);
                if (providersToCall != null && providersToCall.Count > 0)
                {
                    FriendlyUrlOptions options = UrlRewriterUtils.GetOptionsFromSettings(settings);
                    foreach (ExtensionUrlProvider provider in providersToCall)
                    {
                        activeProvider = provider; // for error handling
                        redirected     = provider.CheckForRedirect(result.TabId, result.PortalId, result.HttpAlias,
                                                                   requestUri, queryStringCol, options, out location,
                                                                   ref messages);
                        if (redirected)
                        {
                            result.FinalUrl = location;
                            result.Reason   = RedirectReason.Module_Provider_Redirect;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // log module provider exception
                LogModuleProviderExceptionInRequest(ex, "500 Internal Server Error", activeProvider, result, messages);

                // return defaults
                redirected = false;
                location   = string.Empty;
                string providerName = "Unknown";
                if (activeProvider != null)
                {
                    providerName = activeProvider.ProviderConfig.ProviderName;
                }

                if (result != null)
                {
                    result.DebugMessages.Add("Exception in provider [" + providerName + "] :" + ex.Message);
                }
            }

            return(redirected);
        }
コード例 #5
0
        protected string CleanNameForUrl(string urlValue, FriendlyUrlOptions options)
        {
            bool   changed;
            string result = options != null
                                ? FriendlyUrlController.CleanNameForUrl(urlValue, options, out changed)
                                : FriendlyUrlController.CleanNameForUrl(urlValue, null, out changed);

            return(result);
        }
コード例 #6
0
        protected string CleanNameForUrl(string urlValue, FriendlyUrlOptions options)
        {
            bool changed;
            string result = options != null
                                ? FriendlyUrlController.CleanNameForUrl(urlValue, options, out changed)
                                : FriendlyUrlController.CleanNameForUrl(urlValue, null, out changed);

            return result;
        }
コード例 #7
0
        public FriendlyUrlOptions Clone()
        {
            var cloned = new FriendlyUrlOptions
            {
                PunctuationReplacement = PunctuationReplacement,
                SpaceEncoding          = SpaceEncoding,
                MaxUrlPathLength       = MaxUrlPathLength,
                ConvertDiacriticChars  = ConvertDiacriticChars,
                PageExtension          = PageExtension,
                RegexMatch             = RegexMatch,
                ReplaceCharWithChar    = ReplaceCharWithChar,
                IllegalChars           = IllegalChars,
                ReplaceChars           = ReplaceChars
            };

            return(cloned);
        }
コード例 #8
0
 /// <summary>
 /// Return an extended FriendlyUrlOptions object for Custom URLs checkings
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public static FriendlyUrlOptions ExtendOptionsForCustomURLs(FriendlyUrlOptions options)
 {
     var result = new FriendlyUrlOptions
     {
         PunctuationReplacement = options.PunctuationReplacement,
         SpaceEncoding = options.SpaceEncoding,
         MaxUrlPathLength = options.MaxUrlPathLength,
         ConvertDiacriticChars = options.ConvertDiacriticChars,
         RegexMatch = options.RegexMatch.Replace("[^", "[^./"),
         IllegalChars = options.IllegalChars.Replace("/", ""),
         ReplaceChars = options.ReplaceChars.Replace("/", ""),
         ReplaceDoubleChars = options.ReplaceDoubleChars,
         ReplaceCharWithChar = options.ReplaceCharWithChar,
         PageExtension = options.PageExtension
     };
     return result;
 }
コード例 #9
0
        /// <summary>
        /// Get the tab path for the supplied Tab
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="options"></param>
        /// <param name="parentTraceId"></param>
        /// <returns></returns>
        internal static string GetFriendlyUrlTabPath(TabInfo tab, FriendlyUrlOptions options, Guid parentTraceId)
        {
            string baseTabPath = tab.TabPath.Replace("//", "/").TrimStart('/');
            if (options.CanGenerateNonStandardPath)
            {
                //build up a non-space version of the tab path 
                baseTabPath = BuildTabPathWithReplacement(tab, options, parentTraceId);
                baseTabPath = baseTabPath.Replace("//", "/");

                //automatic diacritic conversion
                if (options.ConvertDiacriticChars)
                {
                    bool diacriticsChanged;
                    baseTabPath = ReplaceDiacritics(baseTabPath, out diacriticsChanged);
                }
            }
            return baseTabPath;
        }
コード例 #10
0
        /// <summary>
        /// Return an extended FriendlyUrlOptions object for Custom URLs checkings.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static FriendlyUrlOptions ExtendOptionsForCustomURLs(FriendlyUrlOptions options)
        {
            var result = new FriendlyUrlOptions
            {
                PunctuationReplacement = options.PunctuationReplacement,
                SpaceEncoding          = options.SpaceEncoding,
                MaxUrlPathLength       = options.MaxUrlPathLength,
                ConvertDiacriticChars  = options.ConvertDiacriticChars,
                RegexMatch             = options.RegexMatch.Replace("[^", "[^./"),
                IllegalChars           = options.IllegalChars.Replace("/", string.Empty),
                ReplaceChars           = options.ReplaceChars.Replace("/", string.Empty),
                ReplaceDoubleChars     = options.ReplaceDoubleChars,
                ReplaceCharWithChar    = options.ReplaceCharWithChar,
                PageExtension          = options.PageExtension,
            };

            return(result);
        }
コード例 #11
0
 private static string AppendToTabPath(string path, TabInfo tab, FriendlyUrlOptions options, out bool modified)
 {
     string tabName = tab.TabName;
     var result = new StringBuilder(tabName.Length);
     //922 : change to harmonise cleaning of tab + other url name items
     tabName = FriendlyUrlController.CleanNameForUrl(tabName, options, out modified);
     if (!modified
         && string.IsNullOrEmpty(options.PunctuationReplacement) == false
         && tab.TabName.Contains(" ")
         && tabName.Contains(" ") == false)
     {
         modified = true;
         //spaces replaced - the modified parameter is for all other replacements but space replacements
     }
     result.Append(tabName);
     result.Insert(0, "//");
     result.Insert(0, path); //effectively adds result to the end of the path
     return result.ToString();
 }
コード例 #12
0
        /// <summary>
        /// Get the tab path for the supplied Tab
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="options"></param>
        /// <param name="parentTraceId"></param>
        /// <returns></returns>
        internal static string GetFriendlyUrlTabPath(TabInfo tab, FriendlyUrlOptions options, Guid parentTraceId)
        {
            string baseTabPath = tab.TabPath.Replace("//", "/").TrimStart('/');

            if (options.CanGenerateNonStandardPath)
            {
                //build up a non-space version of the tab path
                baseTabPath = BuildTabPathWithReplacement(tab, options, parentTraceId);
                baseTabPath = baseTabPath.Replace("//", "/");

                //automatic diacritic conversion
                if (options.ConvertDiacriticChars)
                {
                    bool diacriticsChanged;
                    baseTabPath = ReplaceDiacritics(baseTabPath, out diacriticsChanged);
                }
            }
            return(baseTabPath);
        }
コード例 #13
0
        public static string BuildTabPathWithReplacement(TabInfo tab, FriendlyUrlOptions options, Guid parentTraceId)
        {
            string path = "";

            if ((tab.ParentId > -1))
            {
                TabInfo parentTab = TabController.Instance.GetTab(tab.ParentId, tab.PortalID, false);
                //822 : don't assume parent tab is going to exist - database might be corrupted
                //896 : check to make sure tabid and parentid are different - or stack overflow occurs with terminal loop
                if (parentTab != null && parentTab.TabID != tab.TabID)
                {
                    path = BuildTabPathWithReplacement(parentTab, options, parentTraceId);
                }
            }
            bool modified;

            path = AppendToTabPath(path, tab, options, out modified);

            return(path);
        }
コード例 #14
0
        private static void CheckCharsForReplace(FriendlyUrlOptions options, ref string ch, ref bool replacedUnwantedChars)
        {
            if (!options.ReplaceChars.ToUpperInvariant().Contains(ch.ToUpperInvariant()))
            {
                return;
            }

            if (ch != " ") // if not replacing spaces, which are implied
            {
                replacedUnwantedChars = true;
            }

            ch = options.PunctuationReplacement; // in list of replacment chars

            // If we still have a space ensure it's encoded
            if (ch == " ")
            {
                ch = options.SpaceEncoding;
            }
        }
コード例 #15
0
        private static string AppendToTabPath(string path, TabInfo tab, FriendlyUrlOptions options, out bool modified)
        {
            string tabName = tab.TabName;
            var    result  = new StringBuilder(tabName.Length);

            //922 : change to harmonise cleaning of tab + other url name items
            tabName = FriendlyUrlController.CleanNameForUrl(tabName, options, out modified);
            if (!modified &&
                string.IsNullOrEmpty(options.PunctuationReplacement) == false &&
                tab.TabName.Contains(" ") &&
                tabName.Contains(" ") == false)
            {
                modified = true;
                //spaces replaced - the modified parameter is for all other replacements but space replacements
            }
            result.Append(tabName);
            result.Insert(0, "//");
            result.Insert(0, path); //effectively adds result to the end of the path
            return(result.ToString());
        }
コード例 #16
0
 /// <summary>
 /// Return a FriendlyUrlOptions object from the provider settings
 /// </summary>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static FriendlyUrlOptions GetOptionsFromSettings(FriendlyUrlSettings settings)
 {
     var options = new FriendlyUrlOptions
         {
             PunctuationReplacement = (settings.ReplaceSpaceWith != FriendlyUrlSettings.ReplaceSpaceWithNothing) 
                                             ? settings.ReplaceSpaceWith 
                                             : String.Empty,
             SpaceEncoding = settings.SpaceEncodingValue,
             MaxUrlPathLength = 200,
             ConvertDiacriticChars = settings.AutoAsciiConvert,
             RegexMatch = settings.RegexMatch,
             IllegalChars = settings.IllegalChars,
             ReplaceChars = settings.ReplaceChars,
             ReplaceDoubleChars = settings.ReplaceDoubleChars,
             ReplaceCharWithChar = settings.ReplaceCharacterDictionary,
             PageExtension = (settings.PageExtensionUsageType == PageExtensionUsageType.Never) 
                                     ? "" 
                                     : settings.PageExtension
         };
     return options;
 }
コード例 #17
0
        /// <summary>
        /// Return a FriendlyUrlOptions object from the provider settings.
        /// </summary>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static FriendlyUrlOptions GetOptionsFromSettings(FriendlyUrlSettings settings)
        {
            var options = new FriendlyUrlOptions
            {
                PunctuationReplacement = (settings.ReplaceSpaceWith != FriendlyUrlSettings.ReplaceSpaceWithNothing)
                                                    ? settings.ReplaceSpaceWith
                                                    : string.Empty,
                SpaceEncoding         = settings.SpaceEncodingValue,
                MaxUrlPathLength      = 200,
                ConvertDiacriticChars = settings.AutoAsciiConvert,
                RegexMatch            = settings.RegexMatch,
                IllegalChars          = settings.IllegalChars,
                ReplaceChars          = settings.ReplaceChars,
                ReplaceDoubleChars    = settings.ReplaceDoubleChars,
                ReplaceCharWithChar   = settings.ReplaceCharacterDictionary,
                PageExtension         = (settings.PageExtensionUsageType == PageExtensionUsageType.Never)
                                            ? string.Empty
                                            : settings.PageExtension,
            };

            return(options);
        }
コード例 #18
0
        internal static bool CheckUserProfileReplacement(string newPath,
                                                            TabInfo tab,
                                                            PortalSettings portalSettings,
                                                            FriendlyUrlSettings settings,
                                                            FriendlyUrlOptions options,
                                                            out string changedPath,
                                                            out bool changeToSiteRoot,
                                                            out bool allowOtherParameters,
                                                            ref List<string> meessages,
                                                            Guid parentTraceId)
        {
            if (meessages == null)
            {
                meessages = new List<string>();
            }
            bool urlWasChanged = false;

            //initialise defaults to always return valid items
            changedPath = newPath;
            changeToSiteRoot = false;
            allowOtherParameters = true;

            //determine if this url should be converted to a userprofile url by checking the saved rules matching the tab/portalid
            if (portalSettings != null && tab.PortalID == portalSettings.PortalId &&
                    (tab.TabID == portalSettings.UserTabId || portalSettings.UserTabId == -1 ||
                        tab.ParentId == portalSettings.UserTabId)) //-1 == all tabs in portal
            {
                int userId;
                string rawUserId, remainingPath;
                //split the userid and other profile parameters from the friendly url path, 
                //and return the userid and remaining parts as separate items
                SplitUserIdFromFriendlyUrlPath(newPath,
                                                "UserId",
                                                "",
                                                out rawUserId,
                                                out remainingPath);
                if (rawUserId != null)
                {
                    meessages.Add("User Profile Url : RawUserId = " + rawUserId + " remainingPath = " + remainingPath);
                }
                else
                {
                    meessages.Add("User Profile Url : RawUserId = " + "null" + " remainingPath = " + remainingPath);
                }

                //the rawuserid is just the string representation of the userid from the path.  
                //It should be considered 'untrusted' until cleaned up, 
                //converted to an int and checked against the database
                if (!String.IsNullOrEmpty(rawUserId) && Int32.TryParse(rawUserId, out userId))
                {
                    bool doReplacement = false;
                    string urlName = String.Empty;

                    //Get the User
                    var user = UserController.GetUserById(portalSettings.PortalId, userId);

                    if (user != null && !String.IsNullOrEmpty(user.VanityUrl))
                    {
                        doReplacement = true;
                        urlName = (!String.IsNullOrEmpty(settings.VanityUrlPrefix)) ? String.Format("{0}/{1}", settings.VanityUrlPrefix, user.VanityUrl) : user.VanityUrl;
                        urlWasChanged = true;
                    }

                    if (doReplacement)
                    {
                        //check to see whether this is a match on the parentid or not
                        if (portalSettings.UserTabId == tab.ParentId && portalSettings.UserTabId > -1)
                        {
                            //replacing for the parent tab id
                            string childTabPath = TabIndexController.GetTabPath(tab, options, parentTraceId);
                            if (string.IsNullOrEmpty(childTabPath) == false)
                            {
                                //remove the parent tab path from the child tab path
                                var tc = new TabController();
                                TabInfo profilePage = tc.GetTab(tab.ParentId, tab.PortalID, false);
                                string profilePagePath = TabIndexController.GetTabPath(profilePage, options, parentTraceId);
                                if (childTabPath.Contains(profilePagePath))
                                {
                                    //only replace when the child tab path contains the parent path - if it's a custom url that 
                                    //doesn't incorporate the parent path, then leave it alone
                                    childTabPath = childTabPath.Replace(profilePagePath, "");
                                    childTabPath = childTabPath.Replace("//", "/");
                                    urlName += FriendlyUrlController.EnsureLeadingChar("/", childTabPath);
                                }
                            }
                        }
                        changedPath = "/" + urlName;
                        //append any extra remaining path value to the end
                        if (!string.IsNullOrEmpty(remainingPath))
                        {
                            if (remainingPath.StartsWith("/") == false)
                            {
                                changedPath += "/" + remainingPath;
                            }
                            else
                            {
                                changedPath += remainingPath;
                            }
                        }
                        urlWasChanged = true;
                        changeToSiteRoot = true; //we will be doing domain.com/urlname
                        allowOtherParameters = false;
                        //can't have any others (wouldn't have matched in the regex if there were)
                    }
                    else
                    {
                        meessages.Add("User Profile : doReplacement = false");
                    }
                }
            }
            return urlWasChanged;
        }
コード例 #19
0
 /// <summary>
 /// Transforms a friendly Url into a querystring.  Used as input into the rewriting process, after the Url Rewriting process has identified the correct DNN Page.
 /// </summary>
 /// <param name="urlParms">string array of the friendly Url Path elements, separated by /</param>
 /// <param name="tabId">TabId of page the Friendly Url </param>
 /// <param name="portalId">PortalId of the Friendly Url</param>
 /// <remarks>This method will be only called if there is no match between the Page Index entries this Provider supplies via the 'CreatePageIndex' method.  This method is called
 /// when a DNN page match is found in the requested path, and there are other parameters behind the page path. You should only return a TabId in the querystring, when the ChangeFriendlyUrl function is returning 'true' for the output value of 'useDnnPagePath'.</remarks>
 /// <example>
 /// Given a Url of example.com/pagename/key/value - this method will be called with key,value in the urlParms array with a page match on 'pagename'.  The method should return 'key=value'.
 /// Or, if given a Url of example.com/pagename/my-friendly-module-url, it should transform 'my-friendly-module-url' into whatever the module actually uses to build content.  This might mean returning 'article=2354' derived from doing a specific lookup on 'my-friendly-module-url'.
 /// Warning: It's unwise to do a specific database lookup for each call of this method.  This method needs to be high-performance so should use a stateless method (ie, regex parse) or, if looking up database values, cached hashtables or thread-safe dictionaries.
 /// </example>
 /// <returns>Querystring value in key=value format, which will be used as an input to the rewriting function.</returns>
 public abstract string TransformFriendlyUrlToQueryString(string[] urlParms, 
                                                             int tabId, int portalId,
                                                             FriendlyUrlOptions options, 
                                                             string cultureCode,
                                                             PortalAliasInfo portalAlias, 
                                                             ref List<string> messages,
                                                             out int status, 
                                                             out string location);
コード例 #20
0
        public static string CleanNameForUrl(string urlName, FriendlyUrlOptions options, out bool replacedUnwantedChars)
        {
            replacedUnwantedChars = false;
            //get options
            if (options == null)
            {
                options = new FriendlyUrlOptions();
            }
            bool convertDiacritics = options.ConvertDiacriticChars;
            string regexMatch = options.RegexMatch;
            string illegalChars = options.IllegalChars;
            string replaceWith = options.PunctuationReplacement;
            string replaceChars = options.ReplaceChars;
            bool replaceDoubleChars = options.ReplaceDoubleChars;
            Dictionary<string, string> replacementChars = options.ReplaceCharWithChar;

            if (urlName == null)
            {
                urlName = "";
            }
            var result = new StringBuilder(urlName.Length);
            int i = 0;
            int last = urlName.ToCharArray().GetUpperBound(0);
            string normalisedUrl = urlName;
            if (convertDiacritics)
            {
                normalisedUrl = urlName.Normalize(NormalizationForm.FormD);
                if (string.CompareOrdinal(normalisedUrl, urlName) != 0)
                {
                    replacedUnwantedChars = true; //replaced an accented character
                }
            }
            bool doublePeriod = false;
            foreach (char c in normalisedUrl)
            {
                //look for a double period in the name
                if (!doublePeriod && c == '.' && i > 0 && urlName[i - 1] == '.')
                {
                    doublePeriod = true;
                }
                //use string for manipulation
                string ch = c.ToString();
                //do replacement in pre-defined list?
                if (replacementChars != null && replacementChars.ContainsKey(c.ToString()))
                {
                    //replace with value
                    ch = replacementChars[c.ToString()];
                    replacedUnwantedChars = true;
                }
                else
                {
                    //not in replacement list, check if valid char
                    if (Regex.IsMatch(ch, regexMatch, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
                    {
                        //check replace character with the punctuation replacmenet
                        if (replaceChars.ToLower().Contains(ch.ToLower()))
                        {
                            ch = replaceWith; //in list of replacment chars
                            if (ch != " ") // if not replacing spaces, which are implied
                            {
                                replacedUnwantedChars = true;
                            }
                        }
                        else
                        {
                            ch = ""; //not a replacement or allowed char, so doesn't go into Url
                            replacedUnwantedChars = true;
                            //if we are here, this character isn't going into the output Url
                        }
                    }
                    else
                    {
                        //this char is allowed because it didn't match the regexMatch pattern
                        //however we may still want to replace it in Urls
                        if (illegalChars.ToLower().Contains(ch.ToLower()))
                        {
                            ch = ""; //illegal character, removed from list
                            replacedUnwantedChars = true;
                        }
                        else
                        {
                            //but we also want to check the list of illegal chars - these must never be allowed,
                            //even if the settings inadvertently let them through.  This is a double check
                            //to prevent accidental modification to regex taking down a site
                            if (replaceChars.ToLower().Contains(ch.ToLower()))
                            {
                                if (ch != " ") // if not replacing spaces, which are implied
                                {
                                    replacedUnwantedChars = true;
                                }
                                ch = replaceWith; //in list of replacment chars
                                
                                //If we still have a space ensure its encoded
                                if (ch == " ")
                                {
                                    ch = options.SpaceEncoding;
                                }
                            }
                        }
                    }
                }

                if (i == last)
                {
                    //834 : strip off last character if it is a '.'
                    if (!(ch == "-" || ch == replaceWith || ch == "."))
                    {
                        //only append if not the same as the replacement character
                        result.Append(ch);
                    }
                    else
                    {
                        replacedUnwantedChars = true; //last char not added - effectively replaced with nothing.
                    }
                }
                else
                {
                    result.Append(ch);
                }
                i++; //increment counter
            }

            if (doublePeriod)
            {
                result = result.Replace("..", "");
            }
            //replace any duplicated replacement characters by doing replace twice
            //replaces -- with - or --- with -  //749 : ampersand not completed replaced
            if (replaceDoubleChars && !string.IsNullOrEmpty(replaceWith))
            {
                result = result.Replace(replaceWith + replaceWith, replaceWith);
                result = result.Replace(replaceWith + replaceWith, replaceWith);
            }

            return result.ToString();
        }
コード例 #21
0
 public override bool CheckForRedirect(int tabId, int portalid, string httpAlias, Uri requestUri, NameValueCollection queryStringCol, FriendlyUrlOptions options, out string redirectLocation, ref List<string> messages)
 {
     throw new NotImplementedException();
 }
コード例 #22
0
 public override string TransformFriendlyUrlToQueryString(string[] urlParms, int tabId, int portalId, FriendlyUrlOptions options, string cultureCode, PortalAliasInfo portalAlias, ref List<string> messages, out int status, out string location)
 {
     throw new NotImplementedException();
 }
コード例 #23
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 = "";
                if (cultureCode != null)
                {
                    cultureCodeKey = cultureCode.ToLower();
                }

                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(""))
                                    {
                                        customTabPath = tabpaths[""];
                                        //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 == "" && 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;
        }
コード例 #24
0
 public FriendlyUrlOptions Clone()
 {
     var cloned = new FriendlyUrlOptions
         {
             PunctuationReplacement = PunctuationReplacement,
             SpaceEncoding = SpaceEncoding,
             MaxUrlPathLength = MaxUrlPathLength,
             ConvertDiacriticChars = ConvertDiacriticChars,
             PageExtension = PageExtension,
             RegexMatch = RegexMatch,
             ReplaceCharWithChar = ReplaceCharWithChar,
             IllegalChars = IllegalChars,
             ReplaceChars = ReplaceChars
         };
     return cloned;
 }
コード例 #25
0
        /// <summary>
        /// Returns the tab path of the base DNN tab.  Ie /Home or /Somepage/SomeOtherPage
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="options"></param>
        /// <param name="parentTraceId"></param>
        /// <remarks>Will remove // from the tabPath as stored in the Tabs object/table</remarks>
        /// <returns></returns>
        internal static string GetTabPath(TabInfo tab, FriendlyUrlOptions options, Guid parentTraceId)
        {
            string tabPath = null;
            if (options.CanGenerateNonStandardPath)
            {
                var tpd = FetchTabPathDictionary(tab.PortalID);

                if (tpd != null)
                {
                    using (tpd.GetReadLock())
                    {
                        if (tpd.Count > 0)
                        {
                            //get the path from the dictionary
                            string tabKey = tab.TabID.ToString();
                            if (tpd.ContainsKey(tabKey))
                            {
                                tabPath = tpd[tabKey];
                            }
                        }
                    }
                }
            }

            return tabPath ?? (TabPathHelper.GetFriendlyUrlTabPath(tab, options, parentTraceId));
        }
コード例 #26
0
        private static void CheckCharsForReplace(FriendlyUrlOptions options, ref string ch,
            ref bool replacedUnwantedChars)
        {
            if (!options.ReplaceChars.ToUpperInvariant().Contains(ch.ToUpperInvariant()))
            {
                return;
            }

            if (ch != " ") // if not replacing spaces, which are implied
            {
                replacedUnwantedChars = true;
            }

            ch = options.PunctuationReplacement; //in list of replacment chars

            //If we still have a space ensure it's encoded
            if (ch == " ")
            {
                ch = options.SpaceEncoding;
            }
        }
コード例 #27
0
        public static string CleanNameForUrl(string urlName, FriendlyUrlOptions options, out bool replacedUnwantedChars)
        {
            replacedUnwantedChars = false;

            // get options
            if (options == null)
            {
                options = new FriendlyUrlOptions();
            }

            bool   convertDiacritics  = options.ConvertDiacriticChars;
            Regex  regexMatch         = options.RegexMatchRegex;
            string replaceWith        = options.PunctuationReplacement;
            bool   replaceDoubleChars = options.ReplaceDoubleChars;
            Dictionary <string, string> replacementChars = options.ReplaceCharWithChar;

            if (urlName == null)
            {
                urlName = string.Empty;
            }

            var    result        = new StringBuilder(urlName.Length);
            int    i             = 0;
            string normalisedUrl = urlName;

            if (convertDiacritics)
            {
                normalisedUrl = urlName.Normalize(NormalizationForm.FormD);
                if (!string.Equals(normalisedUrl, urlName, StringComparison.Ordinal))
                {
                    replacedUnwantedChars = true; // replaced an accented character
                }
            }

            int  last         = normalisedUrl.Length - 1;
            bool doublePeriod = false;

            foreach (char c in normalisedUrl)
            {
                // look for a double period in the name
                if (!doublePeriod && i > 0 && c == '.' && normalisedUrl[i - 1] == '.')
                {
                    doublePeriod = true;
                }

                // use string for manipulation
                string ch = c.ToString(CultureInfo.InvariantCulture);

                // do replacement in pre-defined list?
                if (replacementChars != null && replacementChars.ContainsKey(ch))
                {
                    // replace with value
                    ch = replacementChars[ch];
                    replacedUnwantedChars = true;
                }
                else if (convertDiacritics && CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.NonSpacingMark)
                {
                    ch = string.Empty;
                    replacedUnwantedChars = true;
                }
                else
                {
                    // Check if ch is in the replace list
                    CheckCharsForReplace(options, ref ch, ref replacedUnwantedChars);

                    // not in replacement list, check if valid char
                    if (regexMatch.IsMatch(ch))
                    {
                        ch = string.Empty; // not a replacement or allowed char, so doesn't go into Url
                        replacedUnwantedChars = true;

                        // if we are here, this character isn't going into the output Url
                    }
                }

                // Check if the final ch is an illegal char
                CheckIllegalChars(options.IllegalChars, ref ch, ref replacedUnwantedChars);
                if (i == last)
                {
                    // 834 : strip off last character if it is a '.'
                    if (!(ch == "-" || ch == replaceWith || ch == "."))
                    {
                        // only append if not the same as the replacement character
                        result.Append(ch);
                    }
                    else
                    {
                        replacedUnwantedChars = true; // last char not added - effectively replaced with nothing.
                    }
                }
                else
                {
                    result.Append(ch);
                }

                i++; // increment counter
            }

            if (doublePeriod)
            {
                result = result.Replace("..", string.Empty);
            }

            // replace any duplicated replacement characters by doing replace twice
            // replaces -- with - or --- with -  //749 : ampersand not completed replaced
            if (replaceDoubleChars && !string.IsNullOrEmpty(replaceWith))
            {
                result = result.Replace(replaceWith + replaceWith, replaceWith);
                result = result.Replace(replaceWith + replaceWith, replaceWith);
            }

            return(result.ToString());
        }
コード例 #28
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 = "";
                if (cultureCode != null)
                {
                    cultureCodeKey = cultureCode.ToLower();
                }

                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(""))
                                    {
                                        customTabPath = tabpaths[""];
                                        //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 == "" && 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);
        }
コード例 #29
0
        public static string CleanNameForUrl(string urlName, FriendlyUrlOptions options, out bool replacedUnwantedChars)
        {
            replacedUnwantedChars = false;
            //get options
            if (options == null)
            {
                options = new FriendlyUrlOptions();
            }
            bool convertDiacritics = options.ConvertDiacriticChars;
            Regex regexMatch = options.RegexMatchRegex;
            string replaceWith = options.PunctuationReplacement;            
            bool replaceDoubleChars = options.ReplaceDoubleChars;
            Dictionary<string, string> replacementChars = options.ReplaceCharWithChar;

            if (urlName == null)
            {
                urlName = "";
            }
            var result = new StringBuilder(urlName.Length);
            int i = 0;
            string normalisedUrl = urlName;
            if (convertDiacritics)
            {
                normalisedUrl = urlName.Normalize(NormalizationForm.FormD);
                if (!string.Equals(normalisedUrl, urlName, StringComparison.Ordinal))
                {
                    replacedUnwantedChars = true; //replaced an accented character
                }
            }

            int last = normalisedUrl.Length - 1;
            bool doublePeriod = false;
            foreach (char c in normalisedUrl)
            {
                //look for a double period in the name
                if (!doublePeriod && i > 0 && c == '.' && normalisedUrl[i - 1] == '.')
                {
                    doublePeriod = true;
                }

                //use string for manipulation
                string ch = c.ToString(CultureInfo.InvariantCulture);

                //do replacement in pre-defined list?
                if (replacementChars != null && replacementChars.ContainsKey(ch))
                {
                    //replace with value
                    ch = replacementChars[ch];
                    replacedUnwantedChars = true;
                }
                else if (convertDiacritics && CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.NonSpacingMark)
                {
                    ch = string.Empty;
                    replacedUnwantedChars = true;
                }
                else
                {
                    //Check if ch is in the replace list
                    CheckCharsForReplace(options, ref ch, ref replacedUnwantedChars);

                    //not in replacement list, check if valid char
                    if (regexMatch.IsMatch(ch))
                    {
                        ch = ""; //not a replacement or allowed char, so doesn't go into Url
                        replacedUnwantedChars = true;
                        //if we are here, this character isn't going into the output Url                        
                    }
                }

                //Check if the final ch is an illegal char
                CheckIllegalChars(options.IllegalChars, ref ch, ref replacedUnwantedChars);
                if (i == last)
                {
                    //834 : strip off last character if it is a '.'
                    if (!(ch == "-" || ch == replaceWith || ch == "."))
                    {
                        //only append if not the same as the replacement character
                        result.Append(ch);
                    }
                    else
                    {
                        replacedUnwantedChars = true; //last char not added - effectively replaced with nothing.
                    }
                }
                else
                {
                    result.Append(ch);
                }
                i++; //increment counter
            }

            if (doublePeriod)
            {
                result = result.Replace("..", "");
            }
            //replace any duplicated replacement characters by doing replace twice
            //replaces -- with - or --- with -  //749 : ampersand not completed replaced
            if (replaceDoubleChars && !string.IsNullOrEmpty(replaceWith))
            {
                result = result.Replace(replaceWith + replaceWith, replaceWith);
                result = result.Replace(replaceWith + replaceWith, replaceWith);
            }

            return result.ToString();
        }
コード例 #30
0
        private static void AddCustomRedirectsToDictionary(SharedDictionary<string, string> tabIndex,
                                                    Dictionary<string, DupKeyCheck> dupCheck,
                                                    string httpAlias,
                                                    TabInfo tab,
                                                    FriendlyUrlSettings settings,
                                                    FriendlyUrlOptions options,
                                                    ref string rewritePath,
                                                    out int tabPathDepth,
                                                    ref List<string> customHttpAliasesUsed,
                                                    bool isDeleted,
                                                    Guid parentTraceId)
        {
            tabPathDepth = 1;
            var duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabRedirected;
            bool checkForDupUrls = settings.CheckForDuplicateUrls;
            //697 : custom url rewrites with large number of path depths fail because of incorrect path depth calculation
            int maxTabPathDepth = 1;
            string newRewritePath = rewritePath;
            string aliasCulture = null;
            //get the culture for this alias
            var primaryAliases = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(tab.PortalID).ToList();

            if (primaryAliases.Count > 0)
            {
                aliasCulture = primaryAliases.GetCultureByPortalIdAndAlias(tab.PortalID, httpAlias);
            }
            foreach (var redirect in tab.TabUrls)
            {
                //allow for additional qs parameters
                if (!String.IsNullOrEmpty(redirect.QueryString))
                {
                    rewritePath += (redirect.QueryString.StartsWith("&")) ? redirect.QueryString : "&" + redirect.QueryString;
                }

                string redirectTabPath = redirect.Url;
                string redirectedRewritePath = rewritePath;

                //770 : allow for custom portal aliases
                string redirectAlias = httpAlias;
                if (redirect.PortalAliasId > 0)
                {
                    //has a custom portal alias
                    var pac = new PortalAliasController();
                    PortalAliasInfo customAlias = pac.GetPortalAliasByPortalAliasID(redirect.PortalAliasId);
                    if (customAlias != null)
                    {
                        //this will be used to add the Url to the dictionary
                        redirectAlias = customAlias.HTTPAlias;
                        //add to the list of custom aliases used by the portal
                        if (customHttpAliasesUsed == null)
                        {
                            customHttpAliasesUsed = new List<string>();
                        }
                        if (!customHttpAliasesUsed.Contains(redirectAlias))
                        {
                            customHttpAliasesUsed.Add(redirectAlias);
                        }
                    }
                }
                //set the redirect status using the httpStatus
                switch (redirect.HttpStatus)
                {
                    case "301":
                        redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                        ActionType.Redirect301,
                                                                                        RedirectReason.Custom_Redirect);
                        break;
                    case "302":
                        redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                        ActionType.Redirect302,
                                                                                        RedirectReason.Custom_Redirect);
                        break;
                    case "404":
                        redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                        ActionType.Output404,
                                                                                        RedirectReason.Custom_Redirect);
                        break;
                    case "200":
                        //when there is a 200, then replace the 'standard' path
                        newRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(newRewritePath,
                                                                                        ActionType.CheckFor301,
                                                                                        RedirectReason.Custom_Redirect);
                        //672 : replacement urls have preference over all redirects, deleted tabs and standard urls
                        duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabOK;
                        break;
                }
                //check the culture of the redirect to see if it either doesn't match the alias or needs to specify
                //the language when requested
                if (redirect.CultureCode != null)
                {
                    if (redirect.CultureCode != "" && redirect.CultureCode != "Default")
                    {
                        //806 : specify duplicates where the alias culture doesn't match the redirect culture
                        //so that redirect to the best match between alias culture and redirect culture
                        //compare the supplied alias culture with the redirect culture
                        //856 : if alias culture == "" and a custom 301 redirect then redirects are forced
                        if (!string.IsNullOrEmpty(aliasCulture) && aliasCulture != redirect.CultureCode)
                        {
                            //the culture code and the specific culture alias don't match
                            //set 301 check status and set to delete if a duplicate is found
                            redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(
                                                                                redirectedRewritePath,
                                                                                ActionType.CheckFor301,
                                                                                RedirectReason.Custom_Redirect);
                            newRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(newRewritePath,
                                                                                ActionType.CheckFor301,
                                                                                RedirectReason.Custom_Redirect);
                            duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabRedirected;
                        }
                        //add on the culture code for the redirect, so that the rewrite silently sets the culture for the page
                        RewriteController.AddLanguageCodeToRewritePath(ref redirectedRewritePath, redirect.CultureCode);
                    }
                }
                //now add the custom redirect to the tab dictionary
                if (String.Compare(httpAlias, redirectAlias, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AddToTabDict(tabIndex,
                                    dupCheck,
                                    httpAlias,
                                    redirectTabPath,
                                    redirectedRewritePath,
                                    tab.TabID,
                                    duplicateHandlingPreference,
                                    ref tabPathDepth,
                                    checkForDupUrls,
                                    isDeleted);
                }
                else
                {
                    //770 : there is a specific alias for this tab
                    //if not a redirect already, make it a redirect for the wrong (original) rewrite path
                    string wrongAliasRedirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(redirectedRewritePath,
                                                                                                            ActionType.Redirect301,
                                                                                                            RedirectReason.Custom_Tab_Alias);
                    //add in the entry with the specific redirectAlias
                    if (redirectTabPath == "")
                    {
                        //when adding a blank custom Url, also add in a standard tab path url, because any url that also includes querystring data will use the standard tab path
                        string tabPath = GetTabPath(tab, options, parentTraceId);
                        string stdDictRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                                  ActionType.CheckFor301,
                                                                                                  RedirectReason.Custom_Tab_Alias);
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        redirectAlias,
                                        tabPath,
                                        stdDictRewritePath,
                                        tab.TabID,
                                        UrlEnums.TabKeyPreference.TabOK,
                                        ref tabPathDepth,
                                        checkForDupUrls,
                                        isDeleted);
                        //then add in the portal alias with no tabpath (ie like a site root url)
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        redirectAlias,
                                        redirectTabPath,
                                        redirectedRewritePath,
                                        tab.TabID,
                                        duplicateHandlingPreference,
                                        ref tabPathDepth,
                                        checkForDupUrls,
                                        isDeleted);
                        //838 : disabled tabs with custom aliases - still load the settings page without redirect
                        //disabled / not active by date / external url pages cannot navigate to settings page
                        if (tab.DisableLink || !string.IsNullOrEmpty(tab.Url) ||
                           (tab.EndDate < DateTime.Now && tab.EndDate > DateTime.MinValue) ||
                           (tab.StartDate > DateTime.Now && tab.StartDate > DateTime.MinValue))
                        {
                            string settingsUrl = tabPath + "/ctl/Tab";
                            string settingsRewritePath = CreateRewritePath(tab.TabID, redirect.CultureCode, "ctl=Tab");
                            //no redirect on the ctl/Tab url
                            //add in the ctl/tab Url for the custom alias, with no redirect so that the page settings can be loaded
                            AddToTabDict(tabIndex,
                                            dupCheck,
                                            redirectAlias,
                                            settingsUrl,
                                            settingsRewritePath,
                                            tab.TabID,
                                            UrlEnums.TabKeyPreference.TabRedirected,
                                            ref tabPathDepth,
                                            settings.CheckForDuplicateUrls,
                                            isDeleted);
                        }
                    }
                    else
                    {
                        //add in custom entry with different alias
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        redirectAlias,
                                        redirectTabPath,
                                        redirectedRewritePath,
                                        tab.TabID,
                                        duplicateHandlingPreference,
                                        ref tabPathDepth,
                                        checkForDupUrls,
                                        isDeleted);
                        //add in the entry with the original alias, plus an instruction to redirect if it's used
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        httpAlias,
                                        redirectTabPath,
                                        wrongAliasRedirectedRewritePath,
                                        tab.TabID,
                                        duplicateHandlingPreference,
                                        ref tabPathDepth,
                                        checkForDupUrls,
                                        isDeleted);
                    }
                }
                if (tabPathDepth > maxTabPathDepth)
                {
                    maxTabPathDepth = tabPathDepth;
                }
            }
            //return the highest tabpath depth found
            tabPathDepth = maxTabPathDepth;
            //return any changes to the rewritePath
            rewritePath = newRewritePath;
        }
コード例 #31
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="tabId"></param>
 /// <param name="portalid"></param>
 /// <param name="requestUri"></param>
 /// <param name="queryStringCol"></param>
 /// <param name="options"></param>
 /// <param name="messages"></param>
 /// <returns></returns>
 public abstract bool CheckForRedirect(int tabId, 
                                             int portalid, 
                                             string httpAlias, 
                                             Uri requestUri,
                                             NameValueCollection queryStringCol, 
                                             FriendlyUrlOptions options,
                                             out string redirectLocation, 
                                             ref List<string> messages);
コード例 #32
0
        internal static bool TransformFriendlyUrlPath(
            string newUrl,
            string tabKeyVal,
            string[] urlParms,
            bool isSiteRootMatch,
            ref UrlAction result,
            FriendlyUrlSettings settings,
            out string rewrittenUrl,
            out bool newAction,
            ref List <string> messages,
            Guid parentTraceId)
        {
            bool rewriteDone = false;

            rewrittenUrl = newUrl;
            newAction    = false;
            ExtensionUrlProvider activeProvider = null;

            try
            {
                int tabId = result.TabId;
                if (isSiteRootMatch)
                {
                    tabId = RewriteController.SiteRootRewrite;
                }

                List <ExtensionUrlProvider> providersToCall = GetProvidersToCall(
                    tabId,
                    result.PortalId,
                    settings,
                    parentTraceId);
                if (providersToCall != null && providersToCall.Count > 0)
                {
                    // now check for providers by calling the providers
                    int upperBound = urlParms.GetUpperBound(0);

                    // clean extension off parameters array
                    var parms = new string[upperBound + 1];
                    Array.ConstrainedCopy(urlParms, 0, parms, 0, upperBound + 1);
                    if (upperBound >= 0)
                    {
                        bool replaced;
                        parms[upperBound] = RewriteController.CleanExtension(parms[upperBound], settings, out replaced);
                    }

                    // get options from current settings
                    FriendlyUrlOptions options = UrlRewriterUtils.GetOptionsFromSettings(settings);
                    foreach (ExtensionUrlProvider provider in providersToCall)
                    {
                        // set active provider for exception handling
                        activeProvider = provider;

                        // call down to specific providers and see if we get a rewrite
                        string location;
                        int    status;
                        string queryString = provider.TransformFriendlyUrlToQueryString(
                            parms,
                            result.TabId,
                            result.PortalId,
                            options,
                            result.CultureCode,
                            result.PortalAlias,
                            ref messages,
                            out status,
                            out location);
                        if (status == 0 || status == 200) // either not set, or set to '200 OK'.
                        {
                            if (!string.IsNullOrEmpty(queryString) && queryString != newUrl)
                            {
                                rewriteDone = true;

                                // check for duplicate tabIds.
                                string qsRemainder = null;
                                if (Regex.IsMatch(queryString, @"tabid=\d+", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
                                {
                                    // 930 : look for other querystring information in the rewritten Url, or invalid rewritten urls can be created
                                    // pattern to determine which tab matches
                                    // look for any other querystirng information in the already rewritten Url (ie language parameters)
                                    Match rewrittenUrlMatch = RewrittenUrlRegex.Match(rewrittenUrl);
                                    if (rewrittenUrlMatch.Groups["qs"].Success)
                                    {
                                        // keep any other querystring remainders
                                        qsRemainder = rewrittenUrlMatch.Groups["qs"].Captures.Cast <Capture>().Aggregate(string.Empty, (current, qsCapture) => current + qsCapture.Value); // initialise
                                    }

                                    // supplied value overwrites existing value, so remove from the rewritten url
                                    rewrittenUrl = RewrittenUrlRegex.Replace(rewrittenUrl, string.Empty);
                                }

                                if (rewrittenUrl.Contains("?") == false)
                                {
                                    // use a leading ?, not a leading &
                                    queryString = FriendlyUrlController.EnsureNotLeadingChar("&", queryString);
                                    queryString = FriendlyUrlController.EnsureLeadingChar("?", queryString);
                                }
                                else
                                {
                                    // use a leading &, not a leading ?
                                    queryString = FriendlyUrlController.EnsureNotLeadingChar("?", queryString);
                                    queryString = FriendlyUrlController.EnsureLeadingChar("&", queryString);
                                }

                                // add querystring onto rewritten Url
                                rewrittenUrl += queryString;
                                if (qsRemainder != null)
                                {
                                    rewrittenUrl += qsRemainder;
                                }

                                break;
                            }
                        }
                        else
                        {
                            switch (status)
                            {
                            case 301:
                                result.Action   = ActionType.Redirect301;
                                result.Reason   = RedirectReason.Module_Provider_Rewrite_Redirect;
                                result.FinalUrl = location;
                                break;

                            case 302:
                                result.Action   = ActionType.Redirect302;
                                result.Reason   = RedirectReason.Module_Provider_Rewrite_Redirect;
                                result.FinalUrl = location;
                                break;

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

                            case 500:
                                result.Action = ActionType.Output500;
                                break;
                            }

                            newAction = true; // not doing a 200 status
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // log module provider exception
                LogModuleProviderExceptionInRequest(ex, "500 Internal Server Error", activeProvider, result, messages);

                // reset values to initial
                rewriteDone  = false;
                rewrittenUrl = newUrl;
                newAction    = false;
                string providerName = "Unknown";
                if (activeProvider != null)
                {
                    providerName = activeProvider.ProviderConfig.ProviderName;
                }

                if (result != null)
                {
                    result.DebugMessages.Add("Exception in provider [" + providerName + "] :" + ex.Message);
                }
            }

            return(rewriteDone);
        }
コード例 #33
0
        private static int AddTabToTabDict(SharedDictionary<string, string> tabIndex,
                                                Dictionary<string, DupKeyCheck> dupCheck,
                                                string httpAlias,
                                                string aliasCulture,
                                                string customHttpAlias,
                                                PortalInfo thisPortal,
                                                string tabPath,
                                                ref List<string> customAliasesUsed,
                                                TabInfo tab,
                                                FriendlyUrlSettings settings,
                                                FriendlyUrlOptions options,
                                                int homeTabId,
                                                ref Hashtable homePageSkins,
                                                Guid parentTraceId)
        {
            string rewritePath = "";
            int tabPathDepth = 0;
            bool customAliasUsedAndNotCurrent = !String.IsNullOrEmpty(customHttpAlias) && customHttpAlias != httpAlias;

            //592 : check the permanent redirect value
            //736 : 5.5 changes : track tab culture code
            string cultureCode = tab.CultureCode;
            if (String.IsNullOrEmpty(cultureCode))
            {
                cultureCode = aliasCulture;
            }
            bool permanentRedirect = tab.PermanentRedirect;
            //determine the rewrite parameter
            //for deleted, expired or pages not enabled yet, direct to the home page if the setting is enabled
            //534 : tab is disabled, mark as deleted (don't want to cause duplicate tab warnings)
            bool isDeleted = (tab.IsDeleted || tab.DisableLink ||
                             (tab.EndDate < DateTime.Now && tab.EndDate > DateTime.MinValue) ||
                             (tab.StartDate > DateTime.Now && tab.StartDate > DateTime.MinValue));
            if (isDeleted)
            // don't care what setting is, redirect code will decide whether to redirect or 404 - just mark as page deleted && 
            // settings.DeletedTabHandlingValue == DeletedTabHandlingTypes.Do301RedirectToPortalHome)
            {
                //777: force 404 result for all deleted pages instead of relying on 'not found'
                //838 : separate handling for disabled pages
                ActionType action = settings.DeletedTabHandlingType == DeletedTabHandlingType.Do404Error
                                    ? ActionType.Output404
                                    : ActionType.Redirect301;
                rewritePath = tab.DisableLink
                                  ? CreateRewritePath(homeTabId, cultureCode, action, RedirectReason.Disabled_Page)
                                  : CreateRewritePath(homeTabId, cultureCode, action, RedirectReason.Deleted_Page);
            }
            else
            {
                //for all other pages, rewrite to the correct tabId for that page
                //592 : new permanentRedirect value
                if (permanentRedirect)
                {
                    rewritePath = CreateRewritePath(tab.TabID,
                                                    cultureCode,
                                                    ActionType.Redirect301,
                                                    RedirectReason.Tab_Permanent_Redirect);
                }
                else
                {
                    //852 : skin per alias at tab level - if specified
                    if (tab.AliasSkins != null && tab.AliasSkins.ContainsAlias(httpAlias))
                    {
                        TabAliasSkinInfo tas = tab.AliasSkins.FindByHttpAlias(httpAlias);
                        if (tas != null)
                        {
                            string skinSrc = tas.SkinSrc;
                            if (!string.IsNullOrEmpty(skinSrc))
                            {
                                //add skin src into rewrite path
                                rewritePath = CreateRewritePath(tab.TabID, cultureCode, "skinSrc=" + skinSrc);
                            }

                            //now add to the home page skin hashtable if it's the home page.
                            if (homeTabId == tab.TabID)
                            {
                                string key = httpAlias + "::" + cultureCode;
                                string key2 = httpAlias;
                                if (homePageSkins.ContainsKey(key) == false)
                                {
                                    homePageSkins.Add(key, skinSrc);
                                }
                                if (homePageSkins.ContainsKey(key2) == false)
                                {
                                    homePageSkins.Add(key2, skinSrc);
                                }
                            }
                        }
                    }
                    else
                    {
                        rewritePath = CreateRewritePath(tab.TabID, cultureCode);
                    }
                }

                if (thisPortal != null && (thisPortal.UserTabId == tab.TabID || thisPortal.UserTabId == tab.ParentId || thisPortal.UserTabId == -1))
                {
                    //user profile action specified.  If tabid match for this tab, add a do301 check because we want to make
                    //sure that the trimmed Url is used when appropriate
                    rewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                ActionType.CheckFor301,
                                                                                RedirectReason.User_Profile_Url);
                }
            }

            if (tabPath.Replace("//", "/") != tab.TabPath.Replace("//", "/"))
            {
                //when the generated tab path is different to the standard tab path, character substituion has happened
                //this entry is going to have space substitution in it, so it is added into the dictionary with a delete notification and a 301 replaced 
                //this entry is the 'original' (spaces removed) version ie mypage
                string substituteRewritePath = rewritePath;
                if (!isDeleted)
                //if it is deleted, we don't care if the spaces were replaced, or anything else, just take care in deleted handling
                {
                    string replaceSpaceWith = String.Empty;
                    if (settings.ReplaceSpaceWith != FriendlyUrlSettings.ReplaceSpaceWithNothing)
                    {
                        replaceSpaceWith = settings.ReplaceSpaceWith;
                    }
                    substituteRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(substituteRewritePath,
                                                            ActionType.Redirect301,
                                                            tabPath.Contains(replaceSpaceWith)
                                                                ? RedirectReason.Spaces_Replaced
                                                                : RedirectReason.Custom_Redirect);
                }
                //the preference variable determines what to do if a duplicate tab is found already in the dictionary
                var preference = UrlEnums.TabKeyPreference.TabRedirected;
                if (isDeleted)
                {
                    // if the tab is actually deleted, downgrade the preference to 'deleted'.  Any other tabs with the same path that
                    // are redirected but not deleted should take preference
                    preference = UrlEnums.TabKeyPreference.TabDeleted;
                }
                //Note ; if anything else is wrong with this url, (ie, wrong alias) then that will be corrected in a redirect
                AddToTabDict(tabIndex,
                                dupCheck,
                                httpAlias,
                                tab.TabPath,
                                substituteRewritePath,
                                tab.TabID,
                                preference,
                                ref tabPathDepth,
                                settings.CheckForDuplicateUrls,
                                isDeleted);
            }

            //check for permanent redirects as specified in the core dnn permanent redirect property
            if (permanentRedirect)
            {
                AddPermanentRedirectToDictionary(tabIndex,
                                                    dupCheck,
                                                    httpAlias,
                                                    tab,
                                                    tabPath,
                                                    ref rewritePath,
                                                    ref tabPathDepth,
                                                    settings.CheckForDuplicateUrls,
                                                    isDeleted);
            }

            // disabled / not active by date / external url pages cannot navigate to settings page
            if (tab.DisableLink || !string.IsNullOrEmpty(tab.Url) ||
               (tab.EndDate < DateTime.Now && tab.EndDate > DateTime.MinValue) ||
               (tab.StartDate > DateTime.Now && tab.StartDate > DateTime.MinValue))
            {
                string settingsUrl = tabPath.Replace("//", "/") + "/ctl/Tab";
                string settingsRewritePath = CreateRewritePath(tab.TabID, "", "ctl=tab");
                AddToTabDict(tabIndex,
                                dupCheck,
                                httpAlias,
                                settingsUrl,
                                settingsRewritePath,
                                tab.TabID,
                                UrlEnums.TabKeyPreference.TabRedirected,
                                ref tabPathDepth,
                                settings.CheckForDuplicateUrls,
                                isDeleted);
            }

            //777: every tab is added to the dictionary, including those that are deleted 

            //inspect the optional tab redirects and add them as well, keeping track if any are '200' status, meaning the standard Url will be 301, if replaced unfriendly is switched on
            //589 : tab with custom 200 redirects not changing base url to 301 statusa
            AddCustomRedirectsToDictionary(tabIndex,
                                                dupCheck,
                                                httpAlias,
                                                tab,
                                                settings,
                                                options,
                                                ref rewritePath,
                                                out tabPathDepth,
                                                ref customAliasesUsed,
                                                isDeleted,
                                                parentTraceId);

            //if auto ascii conversion is on, do that as well
            if (settings.AutoAsciiConvert)
            {
                bool replacedDiacritic;
                string asciiTabPath = TabPathHelper.ReplaceDiacritics(tabPath, out replacedDiacritic);
                if (replacedDiacritic)
                {
                    ActionType existingAction;
                    RedirectTokens.GetActionFromRewritePath(rewritePath, out existingAction);
                    if (settings.RedirectUnfriendly && existingAction != ActionType.Redirect301)
                    {
                        //add in a tab path, with 301, for the version with the diacritics in
                        string diacriticRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                                ActionType.Redirect301,
                                                                                                RedirectReason.Diacritic_Characters);
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        httpAlias,
                                        tabPath,
                                        diacriticRewritePath,
                                        tab.TabID,
                                        UrlEnums.TabKeyPreference.TabOK,
                                        ref tabPathDepth,
                                        settings.CheckForDuplicateUrls,
                                        isDeleted);
                    }
                    else
                    {
                        //add in the standard version so that the page responds to both the diacritic version
                        AddToTabDict(tabIndex,
                                            dupCheck,
                                            httpAlias,
                                            tabPath,
                                            rewritePath,
                                            tab.TabID,
                                            UrlEnums.TabKeyPreference.TabOK,
                                            ref tabPathDepth,
                                            settings.CheckForDuplicateUrls,
                                            isDeleted);
                    }
                }
                tabPath = asciiTabPath; //switch tabpath to new, ascii-converted version for rest of processing
            }

            //add the 'standard' Url in
            if (tab.TabID == homeTabId && settings.RedirectUnfriendly)
            {
                //home page shoudl be redirected back to the site root
                //899: check for redirect on home page
                rewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                ActionType.CheckFor301,
                                                                                RedirectReason.Site_Root_Home);
                AddToTabDict(tabIndex,
                                dupCheck,
                                httpAlias,
                                tabPath,
                                rewritePath,
                                tab.TabID,
                                UrlEnums.TabKeyPreference.TabOK,
                                ref tabPathDepth,
                                settings.CheckForDuplicateUrls,
                                isDeleted);
            }
            else
            {
                if (customAliasUsedAndNotCurrent && settings.RedirectUnfriendly)
                {
                    //add in the standard page, but it's a redirect to the customAlias
                    rewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                ActionType.Redirect301,
                                                                                RedirectReason.Custom_Tab_Alias);
                    AddToTabDict(tabIndex,
                                    dupCheck,
                                    httpAlias,
                                    tabPath,
                                    rewritePath,
                                    tab.TabID,
                                    UrlEnums.TabKeyPreference.TabRedirected,
                                    ref tabPathDepth,
                                    settings.CheckForDuplicateUrls,
                                    isDeleted);
                }
                else
                {
                    if (customAliasUsedAndNotCurrent && settings.RedirectUnfriendly)
                    {
                        //add in the standard page, but it's a redirect to the customAlias
                        rewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                    ActionType.Redirect301,
                                                                                    RedirectReason.Custom_Tab_Alias);
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        httpAlias,
                                        tabPath,
                                        rewritePath,
                                        tab.TabID,
                                        UrlEnums.TabKeyPreference.TabRedirected,
                                        ref tabPathDepth,
                                        settings.CheckForDuplicateUrls,
                                        isDeleted);
                    }
                    else
                    {
                        //add in the standard page to the dictionary
                        //931 : don't replace existing custom url if this is a redirect or a check for redirect
                        ActionType action;
                        var dupCheckPreference = UrlEnums.TabKeyPreference.TabOK;
                        RedirectTokens.GetActionFromRewritePath(rewritePath, out action);
                        if (action == ActionType.CheckFor301 || action == ActionType.Redirect301 || action == ActionType.Redirect302)
                        {
                            dupCheckPreference = UrlEnums.TabKeyPreference.TabRedirected;
                        }
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        httpAlias,
                                        tabPath,
                                        rewritePath,
                                        tab.TabID,
                                        dupCheckPreference,
                                        ref tabPathDepth,
                                        settings.CheckForDuplicateUrls,
                                        isDeleted);
                    }
                }
            }
            return tabPathDepth;
        }
コード例 #34
0
        internal static bool GetUrlFromExtensionUrlProviders(
            int portalId,
            TabInfo tab,
            FriendlyUrlSettings settings,
            string friendlyUrlPath,
            string cultureCode,
            ref string endingPageName,
            out string changedPath,
            out bool changeToSiteRoot,
            ref List <string> messages,
            Guid parentTraceId)
        {
            bool wasChanged = false;

            changedPath      = friendlyUrlPath;
            changeToSiteRoot = false;
            ExtensionUrlProvider activeProvider = null;

            if (messages == null)
            {
                messages = new List <string>();
            }

            try
            {
                List <ExtensionUrlProvider> providersToCall = GetProvidersToCall(tab.TabID, portalId, settings,
                                                                                 parentTraceId);
                FriendlyUrlOptions options = UrlRewriterUtils.GetOptionsFromSettings(settings);
                foreach (ExtensionUrlProvider provider in providersToCall)
                {
                    activeProvider = provider; // keep for exception purposes
                    bool useDnnPagePath;

                    // go through and call each provider to generate the friendly urls for the module
                    string customPath = provider.ChangeFriendlyUrl(
                        tab,
                        friendlyUrlPath,
                        options,
                        cultureCode,
                        ref endingPageName,
                        out useDnnPagePath,
                        ref messages);

                    if (string.IsNullOrEmpty(endingPageName))
                    {
                        endingPageName = Globals.glbDefaultPage; // set back to default.aspx if provider cleared it
                    }

                    // now check to see if a change was made or not.  Don't trust the provider.
                    if (!string.IsNullOrEmpty(customPath))
                    {
                        // was customPath any different to friendlyUrlPath?
                        if (string.CompareOrdinal(customPath, friendlyUrlPath) != 0)
                        {
                            wasChanged       = true;
                            changedPath      = customPath.Trim();
                            changeToSiteRoot = !useDnnPagePath; // useDNNpagePath means no change to site root.
                            const string format = "Path returned from {0} -> path:{1}, ending Page:{2}, use Page Path:{3}";
                            messages.Add(string.Format(format, provider.ProviderConfig.ProviderName, customPath, endingPageName, useDnnPagePath));
                            break; // first module provider to change the Url is the only one used
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogModuleProviderExceptionInRequest(ex, "500 Internal Server Error", activeProvider, null, messages);

                // reset all values to defaults
                wasChanged       = false;
                changedPath      = friendlyUrlPath;
                changeToSiteRoot = false;
            }

            return(wasChanged);
        }
コード例 #35
0
        internal static bool CheckUserProfileReplacement(string newPath,
                                                         TabInfo tab,
                                                         PortalSettings portalSettings,
                                                         FriendlyUrlSettings settings,
                                                         FriendlyUrlOptions options,
                                                         out string changedPath,
                                                         out bool changeToSiteRoot,
                                                         out bool allowOtherParameters,
                                                         ref List <string> meessages,
                                                         Guid parentTraceId)
        {
            if (meessages == null)
            {
                meessages = new List <string>();
            }
            bool urlWasChanged = false;

            //initialise defaults to always return valid items
            changedPath          = newPath;
            changeToSiteRoot     = false;
            allowOtherParameters = true;

            //determine if this url should be converted to a userprofile url by checking the saved rules matching the tab/portalid
            if (portalSettings != null && tab.PortalID == portalSettings.PortalId &&
                (tab.TabID == portalSettings.UserTabId || portalSettings.UserTabId == -1 ||
                 tab.ParentId == portalSettings.UserTabId))        //-1 == all tabs in portal
            {
                int    userId;
                string rawUserId, remainingPath;
                //split the userid and other profile parameters from the friendly url path,
                //and return the userid and remaining parts as separate items
                SplitUserIdFromFriendlyUrlPath(newPath,
                                               "UserId",
                                               "",
                                               out rawUserId,
                                               out remainingPath);
                if (rawUserId != null)
                {
                    meessages.Add("User Profile Url : RawUserId = " + rawUserId + " remainingPath = " + remainingPath);
                }
                else
                {
                    meessages.Add("User Profile Url : RawUserId = " + "null" + " remainingPath = " + remainingPath);
                }

                //the rawuserid is just the string representation of the userid from the path.
                //It should be considered 'untrusted' until cleaned up,
                //converted to an int and checked against the database
                if (!String.IsNullOrEmpty(rawUserId) && Int32.TryParse(rawUserId, out userId))
                {
                    bool   doReplacement = false;
                    string urlName       = String.Empty;

                    //Get the User
                    var user = UserController.GetUserById(portalSettings.PortalId, userId);

                    if (user != null && !String.IsNullOrEmpty(user.VanityUrl))
                    {
                        doReplacement = true;
                        urlName       = (!String.IsNullOrEmpty(settings.VanityUrlPrefix)) ? String.Format("{0}/{1}", settings.VanityUrlPrefix, user.VanityUrl) : user.VanityUrl;
                        urlWasChanged = true;
                    }

                    if (doReplacement)
                    {
                        //check to see whether this is a match on the parentid or not
                        if (portalSettings.UserTabId == tab.ParentId && portalSettings.UserTabId > -1)
                        {
                            //replacing for the parent tab id
                            string childTabPath = TabIndexController.GetTabPath(tab, options, parentTraceId);
                            if (string.IsNullOrEmpty(childTabPath) == false)
                            {
                                //remove the parent tab path from the child tab path
                                var     tc              = new TabController();
                                TabInfo profilePage     = tc.GetTab(tab.ParentId, tab.PortalID, false);
                                string  profilePagePath = TabIndexController.GetTabPath(profilePage, options, parentTraceId);
                                if (childTabPath.Contains(profilePagePath))
                                {
                                    //only replace when the child tab path contains the parent path - if it's a custom url that
                                    //doesn't incorporate the parent path, then leave it alone
                                    childTabPath   = childTabPath.Replace(profilePagePath, "");
                                    childTabPath   = childTabPath.Replace("//", "/");
                                    remainingPath += FriendlyUrlController.EnsureLeadingChar("/", childTabPath);
                                }
                            }
                        }
                        changedPath = "/" + urlName;
                        //append any extra remaining path value to the end
                        if (!string.IsNullOrEmpty(remainingPath))
                        {
                            if (remainingPath.StartsWith("/") == false)
                            {
                                changedPath += "/" + remainingPath;
                            }
                            else
                            {
                                changedPath += remainingPath;
                            }
                        }
                        urlWasChanged        = true;
                        changeToSiteRoot     = true; //we will be doing domain.com/urlname
                        allowOtherParameters = false;
                        //can't have any others (wouldn't have matched in the regex if there were)
                    }
                    else
                    {
                        meessages.Add("User Profile : doReplacement = false");
                    }
                }
            }
            return(urlWasChanged);
        }
コード例 #36
0
 protected string CleanNameForUrl(string urlValue, FriendlyUrlOptions options, out bool replacedUnwantedChars)
 {
     return FriendlyUrlController.CleanNameForUrl(urlValue, options, out replacedUnwantedChars);
 }
コード例 #37
0
        public static string BuildTabPathWithReplacement(TabInfo tab, FriendlyUrlOptions options, Guid parentTraceId)
        {
            string path = "";
            if ((tab.ParentId > -1))
            {
                var tc = new TabController();
                TabInfo parentTab = tc.GetTab(tab.ParentId, tab.PortalID, false);
                //822 : don't assume parent tab is going to exist - database might be corrupted
                //896 : check to make sure tabid and parentid are different - or stack overflow occurs with terminal loop
                if (parentTab != null && parentTab.TabID != tab.TabID)
                {
                    path = BuildTabPathWithReplacement(parentTab, options, parentTraceId);
                }
            }
            bool modified;
            path = AppendToTabPath(path, tab, options, out modified);

            return path;
        }
コード例 #38
0
 protected string CleanNameForUrl(string urlValue, FriendlyUrlOptions options, out bool replacedUnwantedChars)
 {
     return(FriendlyUrlController.CleanNameForUrl(urlValue, options, out replacedUnwantedChars));
 }
コード例 #39
0
 /// <summary>
 /// Generates a new friendly Url based on the parameters supplied
 /// </summary>
 /// <param name="tab">The current Tab the Friendly Url is for</param>
 /// <param name="friendlyUrlPath">The current friendly Url Path (minus alias) as generated by the Advanced Friendly Url provider</param>
 /// <param name="options">The current friendly Url options that apply to the current portal, as configured within the Extension Url Provider settings.  These include space replacement values and other settings which should be incorporated into the Friendly Url generation.</param>
 /// <param name="endingPageName">The 'pageName' value that comes from the FriendlyUrl API of DNN.  Normally this is the 'default.aspx' value (DotNetNuke.Common.Globals.glbDefaultPage).  A value of 'default.aspx' is discarded. However, it may be a different value for other modules and if not default.aspx will be appended to the end of the Url.  
 /// This is a ref parameter, so it can either be left as-is, or changed to default.aspx or "" if no specific value is required.</param>
 /// <param name="useDnnPagePath">Output parameter, must be set by module Friendly Url Provider.  If true, the /pagename/ part of the Url will be removed, and the Url path will be relative from the site root (example.com/custom-module-path instead of example.com/pagename/custom-module-path)</param>
 /// <param name="messages">A list of information messages used for both debug output and UI information.  Add any informational message to this collection if desired.</param>
 /// <remarks>Note using 'useDnnPagePath' = true requires having a specific tab returned from the TransformFriendlyUrlToQueryString below.  Usage of the 'useDnnPagePath' implies the TransformFriendlyUrlToQueryString method returns a ?tabid=xx value in the querystring.  
 /// It also means the provider level property 'AlwaysUsesDnnPagePath' must return 'false'</remarks>
 /// <returns>Friendly Url for specified values.  Return friendlyUrlPath if no change is made.</returns>
 public abstract string ChangeFriendlyUrl(TabInfo tab, 
                                             string friendlyUrlPath, 
                                             FriendlyUrlOptions options,
                                             string cultureCode, 
                                             ref string endingPageName, 
                                             out bool useDnnPagePath,
                                             ref List<string> messages);
コード例 #40
0
 public override string ChangeFriendlyUrl(TabInfo tab, string friendlyUrlPath, FriendlyUrlOptions options, string cultureCode, ref string endingPageName, out bool useDnnPagePath, ref List<string> messages) 
 {
     throw new NotImplementedException();
 }