Пример #1
0
        public static string GetRedirect(HttpContext currentContext, RedirectReason redirectReason)
        {
            string redirectURL = "";

            if (redirectReason > 0)
            {
                switch (redirectReason)
                {
                case RedirectReason.PageNotFound:
                case RedirectReason.InvalidPermission:
                    redirectURL += "/Oops/" + redirectReason.ToString();
                    break;
                }
            }

            return(redirectURL);
        }
Пример #2
0
        private static string GetRedirectReasonRewriteToken(RedirectReason reason)
        {
            string result = string.Empty;

            switch (reason)
            {
            case RedirectReason.Deleted_Page:
                result = "&rr=dl";
                break;

            case RedirectReason.Disabled_Page:
                // 838 : handle disabled page separately
                result = "&rr=db";
                break;

            case RedirectReason.Tab_Permanent_Redirect:
                result = "&rr=pr";
                break;

            case RedirectReason.Spaces_Replaced:
                result = "&rr=sr";
                break;

            case RedirectReason.Site_Root_Home:
                result = "&rr=hp";
                break;

            case RedirectReason.Diacritic_Characters:
                result = "&rr=dc";
                break;

            case RedirectReason.User_Profile_Url:
                result = "&rr=up";
                break;

            case RedirectReason.Custom_Redirect:
                result = "&rr=cr";
                break;
            }

            return(result);
        }
 /// <summary>
 /// Configures the result object to set the correct Alias redirect
 /// parameters and destination URL
 /// </summary>
 /// <param name="result"></param>
 /// <param name="wrongAlias"></param>
 /// <param name="rightAlias"></param>
 /// <param name="ignoreCustomAliasTabs"></param>
 /// <param name="redirectReason"></param>
 /// <param name="internalAliases"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 private static bool ConfigurePortalAliasRedirect(ref UrlAction result, 
                                                     string wrongAlias, 
                                                     string rightAlias,
                                                     bool ignoreCustomAliasTabs, 
                                                     RedirectReason redirectReason,
                                                     List<InternalAlias> internalAliases,
                                                     FriendlyUrlSettings settings)
 {
     //wrong alias for the portal
     //check to see if the wrong portal alias could be a custom alias for a tab
     bool doRedirect;
     if (ignoreCustomAliasTabs == false) //check out custom alias tabs collection
     {
         //if an alias is a custom tab alias for a specific tab, then don't redirect
         if (CheckIfAliasIsCustomTabAlias(ref result, wrongAlias, settings)) 
             doRedirect = false;
         else
         {
             doRedirect = true;
         }
     }
     else
     {
         doRedirect = true; //do redirect, ignore custom alias entries for tabs
     }
     //check to see if it is an internal alias.  These are used to block redirects
     //to allow for reverse proxy requests, which must change the rewritten alias
     //while leaving the requested alias
     bool internalAliasFound = false;
     if (doRedirect && internalAliases != null && internalAliases.Count > 0)
     {
         if (internalAliases.Any(ia => String.Compare(ia.HttpAlias, wrongAlias, StringComparison.OrdinalIgnoreCase) == 0))
         {
             internalAliasFound = true;
             doRedirect = false;
         }
     }
     //if still need to do redirect, then set the settings that will cause the redirect (redirect not done here)
     if (doRedirect)
     {
         result.Action = ActionType.Redirect301;
         result.Reason = redirectReason;
         string destUrl = result.OriginalPath.Replace(wrongAlias, rightAlias);
         if (redirectReason == RedirectReason.Wrong_Portal_Alias_For_Culture ||
             redirectReason == RedirectReason.Wrong_Portal_Alias_For_Culture_And_Browser)
         {
             destUrl = destUrl.Replace("/language/" + result.CultureCode, "");
         }
         destUrl = CheckForSiteRootRedirect(rightAlias, destUrl);
         result.FinalUrl = destUrl;
     }
     else
     {
         //838 : don't overwrite the reason if already have checkfor301
         // and don't do a check on the basis that an internal alias was found
         if (result.Action != ActionType.CheckFor301 && internalAliasFound == false)
         {
             //set status to 'check for redirect'
             result.Action = ActionType.CheckFor301;
             result.Reason = RedirectReason.Custom_Tab_Alias;
         }
     }
     return doRedirect;
 }
Пример #4
0
 internal static string CreateRewritePath(int tabId, string cultureCode, ActionType action, RedirectReason reason)
 {
     string rewritePath = CreateRewritePath(tabId, cultureCode);
     rewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath, action, reason);
     return rewritePath;
 }
Пример #5
0
 private static string GetRedirectReasonRewriteToken(RedirectReason reason)
 {
     string result = "";
     switch (reason)
     {
         case RedirectReason.Deleted_Page:
             result = "&rr=dl";
             break;
         case RedirectReason.Disabled_Page:
             //838 : handle disabled page separately
             result = "&rr=db";
             break;
         case RedirectReason.Tab_Permanent_Redirect:
             result = "&rr=pr";
             break;
         case RedirectReason.Spaces_Replaced:
             result = "&rr=sr";
             break;
         case RedirectReason.Site_Root_Home:
             result = "&rr=hp";
             break;
         case RedirectReason.Diacritic_Characters:
             result = "&rr=dc";
             break;
         case RedirectReason.User_Profile_Url:
             result = "&rr=up";
             break;
         case RedirectReason.Custom_Redirect:
             result = "&rr=cr";
             break;
     }
     return result;
 }
Пример #6
0
        /// <summary>
        /// DetermineRedirectReasonAndAction extracts the redirect value from the rewrite url and 
        /// returns the new rewritten url, and the reason for the redirection, and an action value for the type of redirect
        /// </summary>
        /// <param name="rewrittenUrl">Rewritten url as found in page dictionary</param>
        /// <param name="result">The current rewrite result.</param>
        /// <param name="wasParms">true if there are parameters in the path, false if not</param>
        /// <param name="settings">current FriendlyUrlSettings object</param>
        /// <param name="action">New action value for UrlAction object</param>
        /// <param name="reason">New redirect reason value for UrlAction object</param>
        /// <param name="newUrl">Url to used for rewrite process</param>
        /// <returns>the new Url, with any replacements done.  Replacements occur when a reason token
        /// was stored in the tab dictionary entry just to indicate a redirect reason.</returns>
        internal static void DetermineRedirectReasonAndAction(string rewrittenUrl, 
                                                                UrlAction result, 
                                                                bool wasParms,
                                                                FriendlyUrlSettings settings, 
                                                                out string newUrl,
                                                                out RedirectReason reason, 
                                                                out ActionType action)
        {
            //init parms
            newUrl = rewrittenUrl;
            action = result.Action;
            reason = result.Reason;

            //get the action type from the rewrite path
            ActionType foundAction;
            bool actionInPath = GetActionFromRewritePath(rewrittenUrl, out foundAction);
            //only overrwrite action if it was found in the rewrite path
            if (actionInPath)
            {
                action = foundAction;
            }
            //get the list of redirect reason tokens from the url
            List<string> redirectReasons = GetRedirectReasonTokensFromRewritePath(rewrittenUrl);

            //when redirect action in path, and redirect reasons are empty, add custom redirect
            if (redirectReasons.Count == 0 && action != ActionType.Continue)
            {
                redirectReasons.Add("cr");
            }
            bool clearActionToken = false;
            foreach (string rrTkn in redirectReasons)
            {
                switch (rrTkn)
                {
                    case "up":
                        //user profile redirect
                        clearActionToken = true;
                        if (wasParms)
                        {
                            if (reason == RedirectReason.Not_Redirected)
                            {
                                if (settings.RedirectOldProfileUrl)
                                {
                                    reason = RedirectReason.User_Profile_Url;
                                    action = ActionType.CheckFor301;
                                }
                                else
                                {
                                    action = ActionType.Continue;
                                }
                            }
                        }
                        else
                        {
                            //if no parms, then we're not doing a userprofileaction redirect
                            reason = RedirectReason.Custom_Redirect;
                            //then check for a 301 redirect
                            action = ActionType.CheckFor301;
                        }

                        break;

                    case "dl":
                    case "db":
                        //deleted tab dl 
                        //disabled tab db
                        clearActionToken = true;
                        //626 Deleted tab hanlding not working properyly - override
                        if (settings.DeletedTabHandlingType == DeletedTabHandlingType.Do404Error)
                        {
                            action = ActionType.Output404; //output a 404 as per settings
                        }

                        //838 : handle disabled pages separately
                        reason = rrTkn == "dl" ? RedirectReason.Deleted_Page : RedirectReason.Disabled_Page;
                        break;

                    case "pr":
                        //pr = permanent redirect
                        reason = RedirectReason.Tab_Permanent_Redirect;
                        clearActionToken = true;
                        break;

                    case "sr":
                        //sr = spaces replaced in url
                        clearActionToken = true;
                        reason = RedirectReason.Spaces_Replaced;
                        break;

                    case "hp":
                        //hp = home page redirect
                        if (wasParms)
                        {
                            //cancel the home page replaced if there were parameters added and page extensions
                            //are in use - otherwise a 404 will occur for the relative path
                            reason = RedirectReason.Not_Redirected;
                            action = ActionType.Continue;
                            clearActionToken = true;
                        }
                        else
                        {
                            reason = RedirectReason.Site_Root_Home;
                            clearActionToken = true;
                        }
                        break;


                    default:
                        //any other redirect with no reason is a custom redirect
                        if (reason == RedirectReason.Not_Redirected)
                        {
                            reason = RedirectReason.Custom_Redirect;
                        }
                        clearActionToken = true;
                        break;
                }
            }
            if (clearActionToken)
            {
                //clear both action and reason
                newUrl = RemoveAnyRedirectTokensAndReasons(newUrl);
            }
            else
            {
                //clear just reason
                newUrl = RemoveAnyRedirectReasons(newUrl);
            }
        }
Пример #7
0
        /// <summary>
        /// Adds on a redirect reason to the rewrite path
        /// </summary>
        /// <param name="existingRewritePath"></param>
        /// <param name="action"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        internal static string AddRedirectReasonToRewritePath(string existingRewritePath, ActionType action, RedirectReason reason)
        {
            string result = existingRewritePath;
            string token, value;
            GetRedirectActionTokenAndValue(action, out token, out value);
            string tokenAndValue = token + "=" + value;
            bool addToken = true;
            //look for existing action
            bool hasDupes;
            Dictionary<string, string> tokensAndValues = GetRedirectTokensAndValuesFromRewritePath(existingRewritePath,
                                                                                                   out hasDupes);
            //can't overwrite existing tokens in certain cases
            if (tokensAndValues.Count > 0)
            {
                //only case we allow is an ovewrite of a do301=check by a do301=true or do302=true
                if (token == "do301" || token == "do302")
                {
                    if (tokensAndValues.ContainsKey("do301") && tokensAndValues["do301"] == "check")
                    {
                        result = existingRewritePath.Replace("do301=check", tokenAndValue);
                    }
                }
                addToken = false; //already done
            }
            if (addToken)
            {
                if (result.Contains(tokenAndValue) == false)
                {
                    if (result.Contains("?"))
                    {
                        result += "&" + tokenAndValue;
                    }
                    else
                    {
                        result += "?" + tokenAndValue;
                    }

                    //the reasonToken helps the rewrite process determine why a redirect is required
                    //after the token is stored in the page dictionary
                    string reasonToken = GetRedirectReasonRewriteToken(reason);
                    if (reasonToken != "")
                    {
                        result += reasonToken;
                    }
                }
                else
                {
                    //special case : add the number of times a 301 has been requested
                    if (tokenAndValue == "do301=true" && reason == RedirectReason.User_Profile_Url)
                    {
                        result += "&num301=2";
                    }
                }
            }
            return result;
        }
Пример #8
0
        /// <summary>
        /// Adds on a redirect reason to the rewrite path.
        /// </summary>
        /// <param name="existingRewritePath"></param>
        /// <param name="action"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        internal static string AddRedirectReasonToRewritePath(string existingRewritePath, ActionType action, RedirectReason reason)
        {
            string result = existingRewritePath;
            string token, value;

            GetRedirectActionTokenAndValue(action, out token, out value);
            string tokenAndValue = token + "=" + value;
            bool   addToken      = true;

            // look for existing action
            bool hasDupes;
            Dictionary <string, string> tokensAndValues = GetRedirectTokensAndValuesFromRewritePath(
                existingRewritePath,
                out hasDupes);

            // can't overwrite existing tokens in certain cases
            if (tokensAndValues.Count > 0)
            {
                // only case we allow is an ovewrite of a do301=check by a do301=true or do302=true
                if (token == "do301" || token == "do302")
                {
                    if (tokensAndValues.ContainsKey("do301") && tokensAndValues["do301"] == "check")
                    {
                        result = existingRewritePath.Replace("do301=check", tokenAndValue);
                    }
                }

                addToken = false; // already done
            }

            if (addToken)
            {
                if (result.Contains(tokenAndValue) == false)
                {
                    if (result.Contains("?"))
                    {
                        result += "&" + tokenAndValue;
                    }
                    else
                    {
                        result += "?" + tokenAndValue;
                    }

                    // the reasonToken helps the rewrite process determine why a redirect is required
                    // after the token is stored in the page dictionary
                    string reasonToken = GetRedirectReasonRewriteToken(reason);
                    if (reasonToken != string.Empty)
                    {
                        result += reasonToken;
                    }
                }
                else
                {
                    // special case : add the number of times a 301 has been requested
                    if (tokenAndValue == "do301=true" && reason == RedirectReason.User_Profile_Url)
                    {
                        result += "&num301=2";
                    }
                }
            }

            return(result);
        }
Пример #9
0
        /// <summary>
        /// DetermineRedirectReasonAndAction extracts the redirect value from the rewrite url and
        /// returns the new rewritten url, and the reason for the redirection, and an action value for the type of redirect.
        /// </summary>
        /// <param name="rewrittenUrl">Rewritten url as found in page dictionary.</param>
        /// <param name="result">The current rewrite result.</param>
        /// <param name="wasParms">true if there are parameters in the path, false if not.</param>
        /// <param name="settings">current FriendlyUrlSettings object.</param>
        /// <param name="action">New action value for UrlAction object.</param>
        /// <param name="reason">New redirect reason value for UrlAction object.</param>
        /// <param name="newUrl">Url to used for rewrite process.</param>
        internal static void DetermineRedirectReasonAndAction(
            string rewrittenUrl,
            UrlAction result,
            bool wasParms,
            FriendlyUrlSettings settings,
            out string newUrl,
            out RedirectReason reason,
            out ActionType action)
        {
            // init parms
            newUrl = rewrittenUrl;
            action = result.Action;
            reason = result.Reason;

            // get the action type from the rewrite path
            ActionType foundAction;
            bool       actionInPath = GetActionFromRewritePath(rewrittenUrl, out foundAction);

            // only overrwrite action if it was found in the rewrite path
            if (actionInPath)
            {
                action = foundAction;
            }

            // get the list of redirect reason tokens from the url
            List <string> redirectReasons = GetRedirectReasonTokensFromRewritePath(rewrittenUrl);

            // when redirect action in path, and redirect reasons are empty, add custom redirect
            if (redirectReasons.Count == 0 && action != ActionType.Continue)
            {
                redirectReasons.Add("cr");
            }

            bool clearActionToken = false;

            foreach (string rrTkn in redirectReasons)
            {
                switch (rrTkn)
                {
                case "up":
                    // user profile redirect
                    clearActionToken = true;
                    if (wasParms)
                    {
                        if (reason == RedirectReason.Not_Redirected)
                        {
                            if (settings.RedirectOldProfileUrl)
                            {
                                reason = RedirectReason.User_Profile_Url;
                                action = ActionType.CheckFor301;
                            }
                            else
                            {
                                action = ActionType.Continue;
                            }
                        }
                    }
                    else
                    {
                        // if no parms, then we're not doing a userprofileaction redirect
                        reason = RedirectReason.Custom_Redirect;

                        // then check for a 301 redirect
                        action = ActionType.CheckFor301;
                    }

                    break;

                case "dl":
                case "db":
                    // deleted tab dl
                    // disabled tab db
                    clearActionToken = true;

                    // 626 Deleted tab hanlding not working properyly - override
                    if (settings.DeletedTabHandlingType == DeletedTabHandlingType.Do404Error)
                    {
                        action = ActionType.Output404;     // output a 404 as per settings
                    }

                    // 838 : handle disabled pages separately
                    reason = rrTkn == "dl" ? RedirectReason.Deleted_Page : RedirectReason.Disabled_Page;
                    break;

                case "pr":
                    // pr = permanent redirect
                    reason           = RedirectReason.Tab_Permanent_Redirect;
                    clearActionToken = true;
                    break;

                case "sr":
                    // sr = spaces replaced in url
                    clearActionToken = true;
                    reason           = RedirectReason.Spaces_Replaced;
                    break;

                case "hp":
                    // hp = home page redirect
                    if (wasParms)
                    {
                        // cancel the home page replaced if there were parameters added and page extensions
                        // are in use - otherwise a 404 will occur for the relative path
                        reason           = RedirectReason.Not_Redirected;
                        action           = ActionType.Continue;
                        clearActionToken = true;
                    }
                    else
                    {
                        reason           = RedirectReason.Site_Root_Home;
                        clearActionToken = true;
                    }

                    break;

                default:
                    // any other redirect with no reason is a custom redirect
                    if (reason == RedirectReason.Not_Redirected)
                    {
                        reason = RedirectReason.Custom_Redirect;
                    }

                    clearActionToken = true;
                    break;
                }
            }

            if (clearActionToken)
            {
                // clear both action and reason
                newUrl = RemoveAnyRedirectTokensAndReasons(newUrl);
            }
            else
            {
                // clear just reason
                newUrl = RemoveAnyRedirectReasons(newUrl);
            }
        }
Пример #10
0
 public static void Redirect(HttpContext currentContext, RedirectReason redirectReason)
 {
     currentContext.Response.Redirect(Utility.GetRedirect(currentContext, redirectReason));
 }