예제 #1
0
        /// <summary>
        /// 呈现首页
        /// </summary>
        /// <param name="context"></param>
        public static void RenderIndex(CmsContext context)
        {
            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }

            //检查缓存
            if (!context.CheckAndSetClientCache())
            {
                return;
            }

            int    siteID  = context.CurrentSite.SiteId;
            string cacheID = String.Concat("cms_s", siteID.ToString(), "_index_page");

            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            if (context.Request["cache"] == "0")
            {
                Cms.Cache.Rebuilt();
            }


            string html = String.Empty;

            if (Settings.Opti_IndexCacheSeconds > 0)
            {
                ICmsCache cache = Cms.Cache;
                object    obj   = cache.Get(cacheID);
                if (obj == null)
                {
                    html = cmsPage.GetIndex(null);
                    cache.Insert(cacheID, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds));
                }
                else
                {
                    html = obj as string;
                }
            }
            else
            {
                //DateTime dt = DateTime.Now;
                html = cmsPage.GetIndex(null);
                //context.Render("<br />"+(DateTime.Now - dt).TotalMilliseconds.ToString() + "<br />");
            }

            //response.AddHeader("Cache-Control", "max-age=" + maxAge.ToString());
            context.Render(html);
        }
예제 #2
0
        /// <summary>
        /// 呈现首页
        /// </summary>
        /// <param name="context"></param>
        public static void RenderIndex(CmsContext context)
        {
            //检测网站状态
            if (!context.CheckSiteState()) return;

            //检查缓存
            if (!context.CheckAndSetClientCache()) return;

        	int siteID=context.CurrentSite.SiteId;
        	string cacheID=String.Concat("cms_s",siteID.ToString(),"_index_page");
        	
        	ICmsPageGenerator cmsPage=new PageGeneratorObject(context);
        	
            if (context.Request["cache"] == "0")
            {
                Cms.Cache.Rebuilt();
            }


            string html = String.Empty;
            if (Settings.Opti_IndexCacheSeconds > 0)
            {
                ICmsCache cache = Cms.Cache;
                object obj = cache.Get(cacheID);
                if (obj == null)
                {
                    html = cmsPage.GetIndex(null);
                    cache.Insert(cacheID, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds));
                }
                else
                {
                    html = obj as string;
                }
            }
            else
            {
                //DateTime dt = DateTime.Now;
                html = cmsPage.GetIndex(null);
                //context.Render("<br />"+(DateTime.Now - dt).TotalMilliseconds.ToString() + "<br />");
            }

            //response.AddHeader("Cache-Control", "max-age=" + maxAge.ToString());
            context.Render(html);
        }
예제 #3
0
        /// <summary>
        /// 呈现首页
        /// </summary>
        /// <param name="context"></param>
        public static void RenderIndex(CmsContext context)
        {
            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }

            //检查缓存
            if (!context.CheckAndSetClientCache())
            {
                return;
            }

            SiteDto site = context.CurrentSite;

            //跳转
            if (!String.IsNullOrEmpty(site.Location))
            {
                //string url;
                //if (Regex.IsMatch(archive.Location, "^http://", RegexOptions.IgnoreCase))
                //{
                //    url = archive.Location;
                //}
                //else
                //{
                //    if (archive.Location.StartsWith("/")) throw new Exception("URL不能以\"/\"开头!");
                //    url = String.Concat(context.SiteDomain, site.Location);
                //}

                context.Response.Redirect(site.Location, true);  //302

                return;
            }


            int    siteID  = site.SiteId;
            string cacheID = String.Concat("cms_s", siteID.ToString(), "_index_page");

            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            if (context.Request["cache"] == "0")
            {
                Cms.Cache.Rebuilt();
            }


            string html = String.Empty;

            if (Settings.Opti_IndexCacheSeconds > 0)
            {
                ICmsCache cache = Cms.Cache;
                object    obj   = cache.Get(cacheID);
                if (obj == null)
                {
                    html = cmsPage.GetIndex(null);
                    cache.Insert(cacheID, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds));
                }
                else
                {
                    html = obj as string;
                }
            }
            else
            {
                //DateTime dt = DateTime.Now;
                html = cmsPage.GetIndex(null);
                //context.Render("<br />"+(DateTime.Now - dt).TotalMilliseconds.ToString() + "<br />");
            }

            //response.AddHeader("Cache-Control", "max-age=" + maxAge.ToString());
            context.Render(html);
        }