Example #1
0
    protected override void OnLoad(EventArgs e)
    {
        Response.AddCacheItemDependency("Pages");

        if (!Index && Header != null)
        {
            HtmlMeta noindex = new HtmlMeta();
            noindex.Name    = "robots";
            noindex.Content = "noindex";
            Header.Controls.Add(noindex);
        }

        if (!IsPostBack)
        {
            if (AutomaticTitle)
            {
                Page.Title = string.Format("{0} - {1}", SessionManager.GetSetting(
                                               "title", "Blog"), Page.Title);
            }

            if (SessionManager.CountersEnabled)
            {
                CounterCache.Increment(Request, Cache, SessionManager);
            }
        }

        base.OnLoad(e);
    }
Example #2
0
        public ActionResult Index(string id, int page = 1)
        {
            //On charge l'ensemble des posts de la catégorie
            IList <Post> posts = new List <Post>();

            using (BlogMvcContext db = new BlogMvcContext())
            {
                int startIndex = page <= 1
                    ? 0
                    : (page - 1) * this.ItemsByPage;

                posts = db.Posts
                        .Where(p => p.Category.slug == id)
                        .Include(p => p.Category)
                        .Include(p => p.User)
                        .OrderByDescending(p => p.Created)
                        .Skip(startIndex)
                        .Take(this.ItemsByPage)
                        .ToList();
            }


            ViewBag.Slug = id;


            //Mise en place d'une dépendance sur le cache
            if (HttpContext.Cache["Post"] == null)
            {
                HttpContext.Cache["Post"] = DateTime.UtcNow.ToString();
            }
            Response.AddCacheItemDependency("Post");


            return(View(posts));
        }
Example #3
0
        protected void HomePage_Load(object sender, System.EventArgs e)
        {
            if (SiteConfig.EnableStartPageCaching && Request.QueryString != null && Request.QueryString["page"] != "admin")
            {
                hideAdminTools = true;
                double seconds = 86400;                 //max 86400 seconds = 24 hours
                // only the default site without any querys will have an expiration
                // time in seconds to the end of day, with query the site will expire
                // after 24 hours
                if (Request.QueryString != null && Request.QueryString.Count == 0)
                {
                    DateTime time        = DateTime.Now;
                    DateTime timeEnd     = new DateTime(time.Year, time.Month, time.Day, 23, 59, 59);
                    TimeSpan endTimeSpan = new TimeSpan(timeEnd.Ticks - time.Ticks);
                    seconds = endTimeSpan.Hours * 60 + endTimeSpan.Minutes * 60 + endTimeSpan.Seconds;
                }
                Response.Cache.SetExpires(DateTime.Now.AddSeconds(seconds));
                Response.Cache.VaryByParams["*"] = true;
                Response.Cache.VaryByHeaders["Accept-Language"] = true;
                Response.Cache.SetCacheability(HttpCacheability.Public);
                Response.Cache.SetValidUntilExpires(true);

                // insert something into the cache so that we can invalidate it when a new entry or comment is made
                this.DataCache.Insert("BlogCoreData", "BlogCoreData", System.Web.Caching.CacheItemPriority.NotRemovable);

                Response.AddCacheItemDependency("BlogCoreData");
                Response.AddFileDependency(SiteConfig.GetConfigFilePathFromCurrentContext());
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string cacheKey = Request.Url.ToString();

            Cache[cacheKey] = new object();
            Response.AddCacheItemDependency(cacheKey);

            string _action = DTRequest.GetQueryString("action");

            if (!string.IsNullOrEmpty(_action) && _action == DTEnums.ActionEnum.Edit.ToString())
            {
                this.action = DTEnums.ActionEnum.Edit.ToString();//修改类型
                if (!int.TryParse(Request.QueryString["id"] as string, out this.id))
                {
                    JscriptMsg("传输参数不正确!", "back");
                    return;
                }
                if (!new BLL.t_bannerimage().Exists(this.id))
                {
                    JscriptMsg("记录不存在或已被删除!", "back");
                    return;
                }
            }
            if (!Page.IsPostBack)
            {
                ChkAdminLevel("sys_banner", DTEnums.ActionEnum.View.ToString()); //检查权限
                Model.manager model = GetAdminInfo();                            //取得管理员信息
                //RoleBind(ddlRoleId, model.role_type);
                if (action == DTEnums.ActionEnum.Edit.ToString())                //修改
                {
                    ShowInfo(this.id);
                }
            }
        }
        public ActionResult Index()
        {
            HttpContext.Cache.Insert("Post", 1);
            Response.AddCacheItemDependency("Post");

            IList <Category> categories = new List <Category>();

            using (GoodBlogDbContext db = new GoodBlogDbContext())
            {
                categories = db.Categories
                             .Include(c => c.Posts)
                             .ToList();
            }

            IList <Post> posts = new List <Post>();

            using (GoodBlogDbContext db = new GoodBlogDbContext())
            {
                posts = db.Posts
                        .OrderByDescending(p => p.Created)
                        .Take(2)
                        .ToList();
            }

            return(PartialView("_SideBar", new SideBarModel()
            {
                Categories = categories, Posts = posts
            }));
        }
Example #6
0
        public ActionResult Index(int page = 1)
        {
            IList <Post> posts = new List <Post>();

            using (GoodBlogDbContext db = new GoodBlogDbContext())
            {
                int startIndex = page <= 1 ? 0 : (page - 1) * this.ItemsByPage;

                posts = db.Posts
                        .Include(p => p.Category)
                        .Include(p => p.User)
                        .OrderByDescending(p => p.Created)
                        .Skip(startIndex)
                        .Take(this.ItemsByPage)
                        .ToList();
            }

            if (HttpContext.Cache["Post"] == null)
            {
                HttpContext.Cache["Post"] = DateTime.UtcNow.ToString();
            }
            Response.AddCacheItemDependency("Post");

            return(View(posts));
        }
Example #7
0
    protected override void OnLoad(EventArgs e)
    {
        try
        {
            string cacheKey = "cacheKey";
            object cache    = HttpContext.Current.Cache[cacheKey];
            if (cache == null)
            {
                HttpContext.Current.Cache[cacheKey] = DateTime.UtcNow.ToString();
            }

            Response.AddCacheItemDependency(cacheKey);
        }
        catch (Exception ex)
        {
            throw new SystemException(ex.Message);
        }
        base.OnLoad(e);
    }