public void ProcessRequest(HttpContext context) { try { String pageNo = context.Request.QueryString["p"]; //String keyWord = Request.QueryString["k"]; if (String.IsNullOrEmpty(pageNo)) return; int recordCount = 0; ClientJsonObj clientJsonObj = new ClientJsonObj(); IRepositoryController m_RepositoryController = new RepositoryController(); clientJsonObj.CurPageBlogs = m_RepositoryController.LoadBlogEntries(WebUtil.ConvertToNumber(pageNo), out recordCount); foreach (Blog b in clientJsonObj.CurPageBlogs) { b.HyperLink = WebUtil.GetBlogHyperLink(b.Id); b.CatBread = m_RepositoryController.LoadCatBreadCrumbsById(b.CategoryId); } clientJsonObj.TotalBlogCount = recordCount; clientJsonObj.PageSize = WayneBlogConstraint.PageSize; JavaScriptSerializer serializer = new JavaScriptSerializer(); String jsonStr = clientJsonObj.CurPageBlogs == null ? "" : serializer.Serialize(clientJsonObj); context.Response.Clear(); //context.Response.CacheControl = "Public"; //context.Response.Expires = 30; // Content will be expired after 30 minutes. //Response.ExpiresAbsolute = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)); WebUtil.WriteAjaxContentWithGZip(context, "application/json", jsonStr); // Approximate 12.6 kb:) //WebUtil.WriteAjaxContent(context, "application/json", jsonStr); // Approximate 77.4 kb //context.Response.End(); } catch (Exception ex) { WayneLogger.WriteLog(ex); } }
protected void Page_Load(object sender, EventArgs e) { string condition = Request.QueryString["Condition"]; if (String.IsNullOrWhiteSpace(condition)) Master.ReturnIndex(); try { IList<Blog> blogList = new List<Blog>(); if (condition == "Time") { int year = Convert.ToInt32(Request.QueryString["Year"]); int month = Convert.ToInt32(Request.QueryString["Month"] == null ? "0" : Request.QueryString["Month"]); int day = Convert.ToInt32(Request.QueryString["Day"] == null ? "0" : Request.QueryString["Day"]); blogList = Blog.LoadByPostDate(year, month, day); String archivePeriod = String.Empty; if (month == 0) archivePeriod = CultureInfo.CurrentUICulture.IetfLanguageTag == "zh-CN" ? year + "年" : year.ToString(); else if (day == 0) archivePeriod = (new DateTime(year, month, 1)).ToString("y", CultureInfo.CurrentUICulture); else archivePeriod = (new DateTime(year, month, day)).ToString("D", CultureInfo.CurrentUICulture); Master.SubTitle = archivePeriod + Resources.BlogRenderer.ArchivePostedBlogsText; Master.MetaKeywords.Content = "Blog Archives, " + archivePeriod + ", Wayne Ye"; Master.MetaDescription.Content = "List of blogs archives within " + archivePeriod; lblInfo.Text = String.Format("<br /><span class=\"HighlightWords\" style=\"font-weight:bold;\">" + Resources.BlogRenderer.ShowArchiveBlogsText + "</span><p> </p>", archivePeriod, blogList.Count); br.WordsForNoRecords = Resources.BlogRenderer.SearchBlogNoRecord; br.DataSource = blogList; br.AdminMode = Master.IsAdminMode(); br.DataBind(); } else if (condition == "Category") { IRepositoryController repositoryController = new RepositoryController(); String catPermalink = Request.QueryString["Cat"]; if (String.IsNullOrWhiteSpace(catPermalink)) { Master.ReturnIndex(); return; } if (catPermalink.EndsWith("/")) // Indicates request URI is end with a slash catPermalink = catPermalink.Remove(catPermalink.Length - 1); int catId = repositoryController.LoadCatIdByPermalink(catPermalink); // Cannot find the specified category, throw exception for logging if (catId == 0) Master.Return404(); Master.SubTitle = String.Format(Resources.BlogRenderer.CategoryPageTitle, catPermalink.Replace("/", "»")); Master.MetaKeywords.Content = "Blog Category, " + catPermalink.Replace("/", ", "); Master.MetaDescription.Content = "List of blogs under category: " + catPermalink.Replace("/", "->"); int totalCount = 0; repositoryController.LoadCategoryBlogs(1, catId, out totalCount); String catBreadcrumbs = repositoryController.LoadCatBreadCrumbsById(catId); lblInfo.Text = String.Format("<br /><span style=\"font-weight:bold;\">" + Resources.BlogRenderer.ShowCategorizedBlogsText + "</span><p> </p>", catBreadcrumbs, totalCount); br.CatId = catId; br.CatPermalink = catPermalink; br.AdminMode = Master.IsAdminMode(); br.LoadCategoryBlogs(); } } catch (CategoryNotFoundException cne) { WayneLogger.WriteLog(cne.Message, "CategoryNotFound.log"); Master.Return404(); } //catch(NullReferenceException nre) //{ // WayneLogger.WriteLog("Null reference!" + nre.Message + ", categoryNames: " + categoryNames.VisuallyPrint() // , "NullRefBug.log"); //} catch (Exception ex) { WayneLogger.WriteLog(ex); Master.ReturnIndex(); } }