Beispiel #1
0
        public structUrl parseUrl(string url)
        {
            var r = new structUrl();
            var path = url;
            if (path.Substring(0, 1) == "/") { path = path.Substring(1); }

            if (path != "")
            {
                //parse path (e.g. /path/to/page )
                var arr = path.Split(new char[] { '+' });
                r.path = arr[0].Replace("-", " ");
                if (arr.Length > 1)
                {
                    //get query after path (e.g. /path/to/page+query+id+7 )
                    r.query = path.Split(new char[] { '+' }, 2)[1].Split(new char[] { '+' });
                }
            }
            else
            {
                r.path = "home";
            }

            //get host
            r.host = S.Request.Host.ToString();
            if (r.host.Substring(r.host.Length - 1) != "/") { r.host += "/"; }

            return r;
        }
Beispiel #2
0
        public void getPageInfoFromUrl(structUrl url)
        {
            string domain = "";
            string subDomain = "";
            string[] domains = GetDomainParts(url.host);
            string title = url.path;
            SqlReader reader;

            domain = domains[1];
            subDomain = domains[0];
            if (string.IsNullOrEmpty(domain)) { domain = url.host; }

            //try to get page info based on domain name
            if (!string.IsNullOrEmpty(url.path))
            {
                //get page info from website domain name & page title
                while (title != "")
                {
                    if (string.IsNullOrEmpty(subDomain))
                    {
                        //domain name & page title
                        var cacheName = "pageinfo_" + url.host + "_" + title;
                        if (S.Server.Cache.ContainsKey(cacheName))
                        {
                            reader = (SqlReader)S.Server.Cache[cacheName];
                        }
                        else {
                            reader = sql.GetPageInfoFromDomainAndTitle(domain, title);
                            S.Server.Cache.Add(cacheName, reader);
                        }
                        if(reader.Rows.Count > 0)
                        {
                            loadPageInfo(reader);
                        }
                    }
                    else
                    {
                        //domain & sub domain & page title
                        var cacheName = "pageinfo_" + url.host + "_" + title;
                        if (S.Server.Cache.ContainsKey(cacheName))
                        {
                            reader = (SqlReader)S.Server.Cache[cacheName];
                            S.Server.Cache.Add(cacheName, reader);
                        }
                        else
                        {
                            reader = sql.GetPageInfoFromSubDomainAndTitle(domain, subDomain, title);
                        }
                        if (reader.Rows.Count > 0)
                        {
                            loadPageInfo(reader);
                        }
                    }
                    if (reader.Rows.Count == 0)
                    {
                        if (title.IndexOf("/") > 0)
                        {
                            //try to get parent page
                            title = String.Join("/", title.Split('/').Reverse().Skip(1).Reverse().ToArray());
                        }
                        else { break; }
                    }
                    else { break; }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(subDomain))
                {
                    //get page info from website home page
                    reader = sql.GetPageInfoFromDomain(domain);
                }
                else
                {
                    //get page info from website sub domain home page
                    reader =  sql.GetPageInfoFromSubDomain(domain, subDomain);
                }
                if (reader.Rows.Count > 0)
                {
                    loadPageInfo(reader);
                }
            }
        }