public SiteMapBuilder(SiteMapBase siteMap)
        {
            Guard.IsNotNull(siteMap, "siteMap");

            this.siteMap = siteMap;
            siteMapNodeBuilder = new SiteMapNodeBuilder(this.siteMap.RootNode);
        }
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void ProcessRequest(HttpContextBase context)
        {
            string      name    = context.Request.QueryString["name"];
            SiteMapBase siteMap = GetSiteMap(name);

            if ((siteMap != null) && siteMap.GenerateSearchEngineMap)
            {
                HttpResponseBase response = context.Response;

                // Set the content type
                response.ContentType = "text/xml";

                // Compress
                if (siteMap.Compress)
                {
                    httpResponseCompressor.Compress(context);
                }

                // Write
                using (StreamWriter sw = new StreamWriter(response.OutputStream, Encoding.UTF8))
                {
                    using (XmlWriter xtw = XmlWriter.Create(sw, new XmlWriterSettings {
                        Indent = false, Encoding = Encoding.UTF8
                    }))
                    {
                        WriteSiteMap(xtw, siteMap, context);
                    }
                }

                // Cache
                httpResponseCacher.Cache(context, TimeSpan.FromMinutes(siteMap.CacheDurationInMinutes));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SiteMapBuilder"/> class.
        /// </summary>
        /// <param name="siteMap">The site map.</param>
        public SiteMapBuilder(SiteMapBase siteMap)
        {
            Guard.IsNotNull(siteMap, "siteMap");

            this.siteMap       = siteMap;
            siteMapNodeBuilder = new SiteMapNodeBuilder(this.siteMap.RootNode);
        }
Beispiel #4
0
        /// <summary>
        /// Called before an action result executes.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public virtual void OnResultExecuting(ResultExecutingContext filterContext)
        {
            Guard.IsNotNull(filterContext, "filterContext");

            SiteMapBase siteMap     = string.IsNullOrEmpty(SiteMapName) ? SiteMaps.DefaultSiteMap : SiteMaps[SiteMapName];
            string      viewDataKey = ViewDataKey ?? DefaultViewDataKey;

            filterContext.Controller.ViewData[viewDataKey] = siteMap;
        }
        private void WriteSiteMap(XmlWriter writer, SiteMapBase siteMap, HttpContextBase httpContext)
        {
            string applicationRoot = httpContext.Request.ApplicationRoot();

            writer.WriteStartDocument();
            writer.WriteStartElement("urlset", SiteMapNameSpace);

            duplicateChecks.Clear();

            WriteNode(writer, siteMap.RootNode, httpContext, applicationRoot);
            siteMap.RootNode.ChildNodes.Each(node => Iterate(writer, node, httpContext, applicationRoot));

            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
        private void WriteSiteMap(XmlWriter writer, SiteMapBase siteMap, HttpContextBase httpContext)
        {
            string applicationRoot = httpContext.Request.ApplicationRoot();

            writer.WriteStartDocument();
            writer.WriteStartElement("urlset", SiteMapNameSpace);

            duplicateChecks.Clear();

            WriteNode(writer, siteMap.RootNode, httpContext, applicationRoot);
            siteMap.RootNode.ChildNodes.Each(node => Iterate(writer, node, httpContext, applicationRoot));

            writer.WriteEndElement();
            writer.WriteEndDocument();
        }