/// <summary>
        /// 呈现分类页
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="page"></param>
        public static void RenderCategory(CmsContext ctx, string catPath, int page)
        {
            int         siteId   = ctx.CurrentSite.SiteId;
            string      html     = String.Empty;
            CategoryDto category = ServiceCall.Instance.SiteService.GetCategory(siteId, catPath);

            if (!(category.ID > 0))
            {
                RenderNotFound(ctx); return;
            }

            if (!catPath.StartsWith(category.Path))
            {
                RenderNotFound(ctx);
                return;
            }

            ICmsPageGenerator cmsPage = new PageGeneratorObject(ctx);

            /*********************************
            *  @ 单页,跳到第一个特殊文档,
            *  @ 如果未设置则最新创建的文档,
            *  @ 如未添加文档则返回404
            *********************************/
            if (String.IsNullOrEmpty(category.Location))
            {
                html = cmsPage.GetCategory(category, page);
                ctx.Render(html);
            }
            else
            {
                string url = category.Location;
                if (category.Location.IndexOf("://") != -1)
                {
                    url = category.Location;
                }
                else
                {
                    if (!category.Location.StartsWith("/"))
                    {
                        url = String.Concat(ctx.SiteAppPath, ctx.SiteAppPath == "/"?"":"/", category.Location);
                    }
                }
                ctx.Response.Redirect(url, true);  //302
            }
        }
Exemple #2
0
        /// <summary>
        /// 呈现分类页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="tag"></param>
        /// <param name="page"></param>
        public static void RenderCategory(CmsContext context, string catPath, int page)
        {
            //检查缓存
            if (!context.CheckAndSetClientCache())
            {
                return;
            }

            int               siteId = context.CurrentSite.SiteId;
            string            html   = String.Empty;
            CategoryDto       category;
            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            category = ServiceCall.Instance.SiteService.GetCategory(siteId, catPath);
            if (!(category.ID > 0))
            {
                RenderNotFound(context); return;
            }

            //获取路径
            string categoryPath = category.Path;
            string appPath      = Cms.Context.SiteAppPath;
            string reqPath      = context.Request.Path.Substring(1);

            if (appPath.Length > 1)
            {
                reqPath = reqPath.Substring(appPath.Length);
            }

            if (!reqPath.StartsWith(categoryPath))
            {
                RenderNotFound(context);
                return;
            }

            /*********************************
            *  @ 单页,跳到第一个特殊文档,
            *  @ 如果未设置则最新创建的文档,
            *  @ 如未添加文档则返回404
            *********************************/
            if (String.IsNullOrEmpty(category.Location))
            {
                html = cmsPage.GetCategory(category, page);
                context.Render(html);
            }
            else
            {
                string url = category.Location;
                if (category.Location.IndexOf("://") != -1)
                {
                    url = category.Location;
                }
                else
                {
                    if (!category.Location.StartsWith("/"))
                    {
                        url = String.Concat(appPath, appPath.Length == 1?String.Empty:"/", category.Location);
                    }
                }
                context.Response.Redirect(url, true);  //302
            }
        }
Exemple #3
0
        /// <summary>
        /// 呈现分类页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="tag"></param>
        /// <param name="page"></param>
        public static void RenderCategory(CmsContext context, string tag, int page)
        {
            //检查缓存
            if (!context.CheckAndSetClientCache())
            {
                return;
            }

            int         siteId = context.CurrentSite.SiteId;
            string      html   = String.Empty;
            CategoryDto category;
            string      allcate = context.Request.Path.Substring(1);



            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            category = ServiceCall.Instance.SiteService.GetCategory(siteId, tag);


            if (!(category.Id > 0))
            {
                RenderNotFound(context); return;
            }

            //获取路径
            string categoryPath = category.UriPath;
            string appPath      = Cms.Context.SiteAppPath;
            string path         = appPath != "/" ? allcate.Substring(appPath.Length) : allcate;

            if (!path.StartsWith(categoryPath))
            {
                RenderNotFound(context);
                return;
            }

            /*********************************
            *  @ 单页,跳到第一个特殊文档,
            *  @ 如果未设置则最新创建的文档,
            *  @ 如未添加文档则返回404
            *********************************/
            if (String.IsNullOrEmpty(category.Location))
            {
                html = cmsPage.GetCategory(category, page);
                context.Render(html);
            }
            else
            {
                string url;

                if (Regex.IsMatch(category.Location, "^http://", RegexOptions.IgnoreCase))
                {
                    url = category.Location;
                }
                else
                {
                    if (!category.Location.StartsWith("/"))
                    {
                        url = String.Concat(appPath, appPath.Length == 1?String.Empty:"/", category.Location);
                    }
                    else
                    {
                        url = category.Location;
                    }
                }


                context.Response.Redirect(url, true);  //302

                //context.Response.StatusCode = 301;
                //context.Render(@"<html><head><meta name=""robots"" content=""noindex""><script>location.href='" +
                //                  url + "';</script></head><body></body></html>");
            }
        }