public override void ProcessRequest(HttpContextBase context) { bool forNews = context.Request.Path.EndsWith("newssitemap.axd", StringComparison.OrdinalIgnoreCase); HandlerCacheItem cacheItem = forNews ? GetNewsSiteMap(context) : GetRegularSiteMap(context); if (GenerateETag) { if (HandleIfNotModified(context, cacheItem.ETag)) { return; } } if (Compress) { context.CompressResponse(); } HttpResponseBase response = context.Response; response.ContentType = "text/xml"; response.Write(cacheItem.Content); if (CacheDurationInMinutes > 0) { if (GenerateETag) { response.Cache.SetETag(cacheItem.ETag); } context.CacheResponseFor(TimeSpan.FromMinutes(CacheDurationInMinutes)); } }
public override void ProcessRequest(HttpContextBase context) { string assetName = context.Request.QueryString["name"]; if (!string.IsNullOrEmpty(assetName)) { AssetElement setting = GetSetting(Configuration, assetName); if (setting != null) { HandlerCacheItem asset = GetAsset(context, setting); if (asset != null) { if (setting.GenerateETag) { if (HandleIfNotModified(context, asset.ETag)) { return; } } HttpResponseBase response = context.Response; // Set the content type response.ContentType = setting.ContentType; // Compress if (setting.Compress) { context.CompressResponse(); } // Write using (StreamWriter sw = new StreamWriter(response.OutputStream)) { sw.Write(asset.Content); } // Cache if (setting.CacheDurationInDays > 0) { // Helpful when hosting in Single Web server if (setting.GenerateETag) { response.Cache.SetETag(asset.ETag); } context.CacheResponseFor(TimeSpan.FromDays(setting.CacheDurationInDays)); } } } } }
public override void ProcessRequest(HttpContextBase context) { const string CacheKey = "openSearchDescription"; XNamespace ns = "http://a9.com/-/spec/opensearch/1.1/"; XNamespace moz = "http://www.mozilla.org/2006/browser/search/"; HandlerCacheItem cacheItem; Cache.TryGet(CacheKey, out cacheItem); if (cacheItem == null) { XElement openSearch = new XElement( ns + "OpenSearchDescription", new XAttribute("xmlns", ns.ToString()), new XAttribute(XNamespace.Xmlns + "moz", moz.ToString()), new XElement(ns + "ShortName", Settings.SiteTitle), new XElement(ns + "Description", Settings.MetaDescription), new XElement(ns + "LongName", "{0} Web Search".FormatWith(Settings.SiteTitle))); UrlHelper url = CreateUrlHelper(context); string rootUrl = Settings.RootUrl; string htmlUrl = url.RouteUrl("Search"); string rssUrl = url.RouteUrl("FeedSearch"); string atomUrl = url.RouteUrl("FeedSearch", new { format = "Atom" }); string tagUrl = url.RouteUrl("SuggestTags"); openSearch.Add( new XElement( ns + "Url", new XAttribute("type", "text/html"), new XAttribute("template", string.Concat("{0}{1}".FormatWith(rootUrl, htmlUrl), "?q={searchTerms}")) ), new XElement( ns + "Url", new XAttribute("type", "application/atom+xml"), new XAttribute("template", string.Concat("{0}{1}".FormatWith(rootUrl, atomUrl), "/{searchTerms}")) ), new XElement( ns + "Url", new XAttribute("type", "application/rss+xml"), new XAttribute("template", string.Concat("{0}{1}".FormatWith(rootUrl, rssUrl), "/{searchTerms}")) ), new XElement( ns + "Url", new XAttribute("type", "application/x-suggestions+json"), new XAttribute("method", "GET"), new XAttribute("template", string.Concat("{0}{1}".FormatWith(rootUrl, tagUrl), "?q={searchTerms}&client=browser")) ) ); openSearch.Add(new XElement(moz + "SearchForm", rootUrl)); string tags = string.Join(" ", Settings.MetaKeywords.Split(',')); openSearch.Add( new XElement(ns + "Contact", Settings.WebmasterEmail), new XElement(ns + "Tags", tags) ); openSearch.Add( new XElement(ns + "Image", new XAttribute("height", "16"), new XAttribute("width", "16"), new XAttribute("type", "image/x-icon"), "{0}/Assets/Images/fav.ico".FormatWith(rootUrl)), new XElement(ns + "Image", new XAttribute("height", "64"), new XAttribute("width", "64"), new XAttribute("type", "image/png"), "{0}/Assets/Images/fav.png".FormatWith(rootUrl)), new XElement(ns + "Image", new XAttribute("type", "image/png"), "{0}/Assets/Images/logo2.png".FormatWith(rootUrl)) ); openSearch.Add( new XElement(ns + "Query", new XAttribute("role", "example"), new XAttribute("searchTerms", "asp.net")), new XElement(ns + "Developer", "{0} Development Team".FormatWith(Settings.SiteTitle)), new XElement(ns + "Attribution", "Search data Copyright (c) {0}".FormatWith(Settings.SiteTitle)), new XElement(ns + "SyndicationRight", "open"), new XElement(ns + "AdultContent", "false"), new XElement(ns + "Language", "en-us"), new XElement(ns + "OutputEncoding", "UTF-8"), new XElement(ns + "InputEncoding", "UTF-8") ); XDocument doc = new XDocument(); doc.Add(openSearch); cacheItem = new HandlerCacheItem { Content = doc.ToXml() }; if ((CacheDurationInDays > 0) && !Cache.Contains(CacheKey)) { Cache.Set(CacheKey, cacheItem, SystemTime.Now().AddDays(CacheDurationInDays)); } } if (GenerateETag) { if (HandleIfNotModified(context, cacheItem.ETag)) { return; } } if (Compress) { context.CompressResponse(); } HttpResponseBase response = context.Response; response.ContentType = "application/opensearchdescription+xml"; response.Write(cacheItem.Content); if (CacheDurationInDays > 0) { if (GenerateETag) { response.Cache.SetETag(cacheItem.ETag); } context.CacheResponseFor(TimeSpan.FromDays(CacheDurationInDays)); } }
public override void ProcessRequest(HttpContextBase context) { const int CountWidthBuffer = 6; HttpRequestBase request = context.Request; string url = request.QueryString["url"]; Color borderColor = GetColor(request.QueryString, "borderColor", Colors.BorderColor); Color textBackColor = GetColor(request.QueryString, "textBackColor", Colors.TextBackColor); Color textForeColor = GetColor(request.QueryString, "textForeColor", Colors.TextForeColor); Color countBackColor = GetColor(request.QueryString, "countBackColor", Colors.CountBackColor); Color countForeColor = GetColor(request.QueryString, "countForeColor", Colors.CountForeColor); int width = GetInteger(request.QueryString, "width", Width); int height = GetInteger(request.QueryString, "height", Height); int borderWidth = GetInteger(request.QueryString, "borderWidth", BorderWidth); string fontName = string.IsNullOrEmpty(request.QueryString["fontName"]) ? FontName : request.QueryString["fontName"]; int fontSize = GetInteger(request.QueryString, "fontSize", FontSize); HttpResponseBase response = context.Response; DateTime storyLastActivityAt = SystemTime.Now(); using (MemoryStream ms = new MemoryStream()) { using (Image image = new Bitmap(width, height, PixelFormat.Format32bppArgb)) { using (Graphics gdi = Graphics.FromImage(image)) { gdi.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; gdi.InterpolationMode = InterpolationMode.HighQualityBicubic; gdi.SmoothingMode = SmoothingMode.HighSpeed; gdi.CompositingQuality = CompositingQuality.HighSpeed; using (Brush borderBrush = new SolidBrush(borderColor)) { gdi.FillRectangle(borderBrush, 0, 0, image.Width, image.Height); } using (Brush textBackgroundBrush = new SolidBrush(textBackColor)) { gdi.FillRectangle(textBackgroundBrush, borderWidth, borderWidth, (image.Width - (borderWidth * 2)), (image.Height - (borderWidth * 2))); } int count = 0; if (url.IsWebUrl()) { IStory story = StoryRepository.FindByUrl(url); if (story != null) { count = story.VoteCount; storyLastActivityAt = story.LastActivityAt; } } using (Font font = new Font(fontName, fontSize, FontStyle.Bold, GraphicsUnit.Pixel)) { SizeF countSize = gdi.MeasureString(count.ToString(Constants.CurrentCulture), font); float textWidth = (image.Width - (countSize.Width + CountWidthBuffer + (borderWidth * 2))); using (Brush textForegroundBrush = new SolidBrush(textForeColor)) { SizeF textSize = gdi.MeasureString(Settings.PromoteText, font); float x = (((textWidth - textSize.Width) / 2) + borderWidth); float y = ((image.Height - textSize.Height) / 2); gdi.DrawString(Settings.PromoteText, font, textForegroundBrush, x, y); } using (Brush countBackgroundBrush = new SolidBrush(countBackColor)) { gdi.FillRectangle(countBackgroundBrush, (textWidth + borderWidth), borderWidth, (countSize.Width + CountWidthBuffer), (image.Height - (borderWidth * 2))); } using (Brush countForegroundBrush = new SolidBrush(countForeColor)) { float x = ((((countSize.Width + CountWidthBuffer) - countSize.Width) / 2) + borderWidth + textWidth); float y = ((image.Height - countSize.Height) / 2); gdi.DrawString(count.ToString(Constants.CurrentCulture), font, countForegroundBrush, x, y); } } } image.Save(ms, ImageFormat.Png); } ms.WriteTo(response.OutputStream); response.ContentType = "image/PNG"; } bool doNotCache; if (!bool.TryParse(request.QueryString["noCache"], out doNotCache)) { doNotCache = false; } if (doNotCache) { context.Response.Cache.SetCacheability(HttpCacheability.NoCache); } else { float durationInMinutes = ((SystemTime.Now() - storyLastActivityAt).TotalDays > Settings.MaximumAgeOfStoryInHoursToPublish) ? ExpiredStoryCacheDurationInMinutes : NewStoryCacheDurationInMinutes; if (durationInMinutes > 0) { context.CacheResponseFor(TimeSpan.FromMinutes(durationInMinutes)); } } }
public override void ProcessRequest(HttpContextBase context) { const string CacheKey = "XrdsDescription"; const string Xrds = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<xrds:XRDS xmlns:xrds=\"xri://$xrds\" xmlns:openid=\"http://openid.net/xmlns/1.0\" xmlns=\"xri://$xrd*($v*2.0)\">" + "<XRD>" + "<Service priority=\"1\">" + "<Type>http://specs.openid.net/auth/2.0/return_to</Type>" + "<URI>{0}</URI>" + "</Service>" + "</XRD>" + "</xrds:XRDS>"; HandlerCacheItem cacheItem; Cache.TryGet(CacheKey, out cacheItem); if (cacheItem == null) { UrlHelper urlHelper = CreateUrlHelper(context); string url = string.Concat(Settings.RootUrl, urlHelper.RouteUrl("OpenId")); string xml = Xrds.FormatWith(url); cacheItem = new HandlerCacheItem { Content = xml }; if ((CacheDurationInDays > 0) && !Cache.Contains(CacheKey)) { Cache.Set(CacheKey, cacheItem, SystemTime.Now().AddDays(CacheDurationInDays)); } } if (GenerateETag) { if (HandleIfNotModified(context, cacheItem.ETag)) { return; } } if (Compress) { context.CompressResponse(); } HttpResponseBase response = context.Response; response.ContentType = "application/xrds+xml"; response.Write(cacheItem.Content); if (CacheDurationInDays > 0) { if (GenerateETag) { response.Cache.SetETag(cacheItem.ETag); } context.CacheResponseFor(TimeSpan.FromDays(CacheDurationInDays)); } Log.Info("Xrds Requested."); }