public override string RewriteUrl(string url)
        {
            var parts = url.Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);

            // If it is an virtual app
            var path         = HttpContext.Current.Request.ApplicationPath;
            var rewrittenUrl = "/";

            if (!path.Equals('/'))
            {
                rewrittenUrl += path;
                if (!path.EndsWith("/"))
                {
                    rewrittenUrl += "/";
                }
            }
            rewrittenUrl += string.Format("{0}", this.friendlyPageName);

            var pageId = "0"; //this is made in order to allow urls formed only with the handler (/site/ been the default). Those urls will be redirected to the portal home.

            regex = new Regex("^\\d+$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            // Need to search for the pageId in the url
            int indexNumber = -1;

            for (int i = 0; i < parts.Length && indexNumber == -1; i++)
            {
                if (regex.IsMatch(parts[i]))
                {
                    indexNumber = i;
                }
            }
            if (indexNumber != -1)
            {
                pageId = parts[indexNumber];
            }

            // Get PageID from the URL
            pageId = UrlRewritingFriendlyUrl.GetPageIDFromPageName(url);

            //pageId = 1.ToString();
            var queryString = string.Format("?pageId={0}", pageId);

            if (parts.Length > 2)
            {
                for (var i = 0; i < indexNumber; i++)
                {
                    var queryStringParam = parts[i];
                    queryStringParam = Regex.Replace(queryStringParam, @" ", "%20");
                    if (queryStringParam.IndexOf(this.defaultSplitter) < 0)
                    {
                        continue;
                    }


                    queryString += string.Format(
                        "&{0}",
                        queryStringParam.Substring(0, queryStringParam.IndexOf(this.defaultSplitter)));
                    queryString += string.Format(
                        "={0}",
                        queryStringParam.Substring(queryStringParam.IndexOf(this.defaultSplitter) + this.defaultSplitter.Length));
                }
            }

            //Agregar los query que haya en el ultimo, y el hash
            //if(parts.Length > 2){
            //    string last = parts[parts.Length - 1];
            //    // Hay algun atributo de query
            //    if(last.IndexOf('?') > 0){
            //        var queryparts = last.Split(new char[] { '&' }, System.StringSplitOptions.RemoveEmptyEntries);
            //        queryparts[0] = queryparts[0].Substring(1, queryparts[0].Length - 1);
            //        queryString += queryparts[0];
            //        // si query parts tiene mas de un &, tiene mas de un atributo
            //        if (queryparts.Length > 1) {
            //            for (int i = 1; i < queryparts.Length - 1; i++) {
            //                queryString += queryparts[i];
            //            }
            //        }

            //    }
            //}
            if (HttpContext.Current.Request.Form["signed_request"] != null)
            {
                queryString += string.Format(
                    "&signed_request={0}",
                    HttpContext.Current.Request.Params["signed_request"]);
            }

            HttpContext.Current.RewritePath(rewrittenUrl, string.Empty, queryString);

            return(rewrittenUrl + queryString);
        }
예제 #2
0
        /// <summary>
        /// Rewrites the URL.
        /// </summary>
        /// <param name="url">The URL to rewrite.</param>
        /// <returns>The rewritten URL.</returns>
        public override string RewriteUrl(string url)
        {
            var handler      = string.Format("/{0}", this.handlerFlag);
            var rewrittenUrl = "";

            var settings = PortalSettings.GetPortalSettingsbyPageID(Portal.PageID, Config.DefaultPortal);

            // [email protected] - 2014/12/16 -  Only when Url contains handler and EnablePageFriendlyUrl = false
            if (url.Contains(handler) && !settings.EnablePageFriendlyUrl)
            {
                rewrittenUrl = url.Substring(0, url.IndexOf(handler));
            }

            var parts = url.Substring(url.IndexOf(handler) + handler.Length).Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);

            rewrittenUrl += string.Format("/{0}", this.friendlyPageName);

            var   pageId = "0"; //this is made in order to allow urls formed only with the handler (/site/ been the default). Those urls will be redirected to the portal home.
            Regex regex  = new Regex("^\\d+$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            // Need to search for the pageId in the url
            int indexNumber = -1;

            // [email protected] - 2014/12/16 -
            //Set the pageid If Enable frindly Url is false
            // if true then set the pageid from URLRewriteFriendlyUrl class
            if (!settings.EnablePageFriendlyUrl)
            {
                for (int i = 0; i < parts.Length && indexNumber == -1; i++)
                {
                    if (regex.IsMatch(parts[i]))
                    {
                        indexNumber = i;
                    }
                }
                if (url.Contains("alias" + this.defaultSplitter))
                {
                    pageId = 0.ToString();
                }
                else if (indexNumber != -1)
                {
                    pageId = parts[indexNumber];
                }
            }
            else
            {
                // [email protected] - 2014/12/16 -  Set when EnableFriendlyUrl is true
                pageId = UrlRewritingFriendlyUrl.GetPageIDFromPageName(url);
            }

            var queryString = string.Format("?pageId={0}", pageId);

            if (parts.Length > 2)
            {
                for (var i = 0; i < indexNumber; i++)
                {
                    var queryStringParam = parts[i];

                    if (queryStringParam.IndexOf(this.defaultSplitter) < 0)
                    {
                        continue;
                    }

                    queryString += string.Format(
                        "&{0}={1}",
                        queryStringParam.Substring(0, queryStringParam.IndexOf(this.defaultSplitter)),
                        queryStringParam.Substring(queryStringParam.IndexOf(this.defaultSplitter) + this.defaultSplitter.Length));
                }
            }
            if (HttpContext.Current.Request.Form["signed_request"] != null)
            {
                queryString += string.Format(
                    "&signed_request={0}",
                    HttpContext.Current.Request.Params["signed_request"]);
            }

            HttpContext.Current.RewritePath(rewrittenUrl, string.Empty, queryString);

            return(rewrittenUrl + queryString);
        }