コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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));
                        }
                    }
                }
            }
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
ファイル: XrdsHandler.cs プロジェクト: aoki1210/kigg
        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.");
        }