コード例 #1
0
        public ActionResult Index(PostPageViewModel currentPage, int year, string slug = "")
        {
            //we want to allow just /year being hit, and redirected to blog home
            if (string.IsNullOrWhiteSpace(slug))
            {
                return(RedirectToAction("Index", "Blog"));
            }

            //try get the post from memcache first
            var post = MemoryCache.GetPost(year, slug);

            if (post != null)
            {
                currentPage.Slug       = post.Slug;
                currentPage.Title      = post.Title;
                currentPage.PostedTime = post.PostedTime;
                currentPage.BodyHtml   = post.BodyHtml;
                currentPage.ReadTime   = post.ReadTime;
                currentPage.Categories = post.Categories;
                currentPage.AuthorName = SettingsCache.GetAuthor();

                //replace defaults in base page
                currentPage.DontIndexPage = post.DontIndexPost;
                currentPage.WindowTitle   = post.Title;
                if (!string.IsNullOrWhiteSpace(post.MetaDescPost))
                {
                    currentPage.MetaDescription = post.MetaDescPost;
                }

                return(View("Post", currentPage));
            }

            return(RedirectToAction("NotFound", "Error"));
        }