示例#1
0
文件: Page.cs 项目: cmcd74/SavvyCMS
        /// <summary>
        /// Custom URL scheme for pages in this project
        /// </summary>
        /// <returns></returns>
        public override string GetUrl(string defaultControllerTemplate)
        {
            string url;

            if ((this.PageIsALink) || this.TemplateCode == "link")
            {
                Logging.trace("[" + this.Title + "]urllink");
                url = Fmt.ReplaceWebsiteBaseUrlPaths(this.LinkUrl);
            }
            else if (this.TemplateCode == "products")
            {
                url = base.GetUrl("Products");
            }
            else if (this.TemplateCode == "articlepage")
            {
                url = base.GetUrl("ArticlePage");
            }
            else if (this.TemplateCode == "resources")
            {
                url = base.GetUrl("Resources");
            }
            else if (this.TemplateCode == "section")                  //section place holder returns first child
            {
                var children = this.ChildPages.Filter(page => page.GetIsActive());
                if (children != null && children.Count > 0)
                {
                    url = children[0].GetUrl();
                }
                else
                {
                    //Web.ErrorMessage = "Page Not Found";
                    url = Web.Root;
                }
            }
            else if (this.URLRewriteTitle.IsNotBlank() && defaultControllerTemplate == "page" && PageCode.IsBlank())
            {
                // user has set up this page with a custom url
                url = Web.Root + "page/" + this.URLRewriteTitle;
                Logging.trace("[" + this.Title + "]urlrw");
            }
            else if (this.PageCode.IsNotBlank())
            {
                if (PageCode.ToLower() == "home")
                {
                    url = Web.Root;
                    //} else	if (PageCode.ToLower() == "accessibility") {
                    //	url = base.GetUrl(defaultControllerTemplate);						//this is how to use a page code, but not be a controller
                }
                else
                {
                    // this is a built in page that corresponds to a controller
                    url = Web.Root + this.PageCode;
                }
                Logging.trace("[" + this.Title + "]urlpg");
            }
            else
            {
                // either a built-in template or a non-custom url (we don't allow custom urls for built-in templates)
                url = base.GetUrl(defaultControllerTemplate);
                Logging.trace("[" + this.Title + "]urlbase");
            }

            if ((this.SwitchToNonSSLMode))               //note this needs testing, maybe path wrong JC 20140625
            {
                url = Web.BaseUrlSSL + url.RemovePrefix("/");;
            }

            return(url);
        }