You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.0 KiB

  1. @using System.Web.Caching;
  2. @{
  3. Page.Title = Blog.Title;
  4. Layout = "~/themes/" + Blog.Theme + "/_Layout.cshtml";
  5. DateTime lastModified = DateTime.MinValue;
  6. if (string.IsNullOrEmpty(Blog.CurrentSlug))
  7. {
  8. Page.ShowPaging = true;
  9. var posts = Blog.GetPosts(Blog.PostsPerPage);
  10. foreach (var post in posts)
  11. {
  12. @RenderPage("~/themes/" + Blog.Theme + "/Post.cshtml", post);
  13. }
  14. if (posts.Any())
  15. {
  16. lastModified = posts.Max(p => p.LastModified);
  17. }
  18. Response.AddCacheItemDependency("posts");
  19. Response.Cache.VaryByParams["page"] = true;
  20. Response.Cache.VaryByParams["category"] = true;
  21. }
  22. else
  23. {
  24. Post post = Blog.IsNewPost ? new Post() : Blog.CurrentPost;
  25. if (Blog.IsNewPost && !User.Identity.IsAuthenticated)
  26. {
  27. FormsAuthentication.RedirectToLoginPage();
  28. }
  29. if (post == null) { throw new HttpException(404, "Post not found"); }
  30. Page.Title = post.Title;
  31. lastModified = post.LastModified;
  32. Response.AddCacheDependency(new CacheDependency(Server.MapPath("~/posts/" + post.ID + ".xml")));
  33. @RenderPage("~/themes/" + Blog.Theme + "/Post.cshtml", post)
  34. }
  35. if (!Request.IsLocal)
  36. {
  37. Response.Cache.AppendCacheExtension("max-age=0");
  38. Response.Cache.SetValidUntilExpires(true);
  39. Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
  40. Response.Cache.SetVaryByCustom("authenticated");
  41. Response.Cache.VaryByParams["slug"] = true;
  42. Response.AddCacheDependency(new CacheDependency(Server.MapPath("~/")));
  43. Response.AddCacheDependency(new CacheDependency(Server.MapPath("~/scripts")));
  44. Response.AddCacheDependency(new CacheDependency(Server.MapPath("~/css")));
  45. Response.AddCacheDependency(new CacheDependency(Server.MapPath("~/themes/" + Blog.Theme)));
  46. Blog.SetConditionalGetHeaders(lastModified, Context);
  47. }
  48. }