We've got a sitemap generator class that inherits IHttpHandler. Because this is in a shared project with multiple sites, I want to ensure that when sitemap.xml is called, the correct tree structure is drawn out based on the site I'm visiting. I figure hooking into the Sitecore pipeline is the key, but can someone guide me to the proper one that I'd replace the standard .NET one with? Thanks much.
To answer your question directly; you would need to get in after the SiteResolver. Since you need to know what site you're on, to deliver your sitemap. It sits near the top in the
<httpRequestBegin> <processor type="Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel" /> <processor type="Sitecore.Pipelines.HttpRequest.EnsureServerUrl, Sitecore.Kernel" /> <processor type="Sitecore.Pipelines.HttpRequest.StartMeasurements, Sitecore.Kernel" /> <processor type="Sitecore.Pipelines.HttpRequest.IgnoreList, Sitecore.Kernel" /> <processor type="Sitecore.Pipelines.HttpRequest.SiteResolver, Sitecore.Kernel" />
So you would not be implementing an IHttpHandler as you suggest, you would instead inherit from
If I may; I'd like to add a few architectural considerations to the mix as well.
Be careful not to "render" your sitemap in real time on these requests. It's usually a very "heavy" operation and you open yourself up quite easily to a denial-of-service attack by doing so.
Instead I propose you add sitemap generation as a scheduled task in Sitecore, to regularly (like hourly/daily/as appropriate) generate sitemaps for each site, and the processor in question only concerns itself with streaming back that generated sitemap to the client.
IHttpHandlers usually execute before a
Sitecore.Context is established - this is exactly the job of the
EDIT: Added based on comments
Creating the sitemaps in the context of a Scheduled Task, you can indeed implement any class you like. Sitecore, however, expects to find the following method signature on whatever class you implement.
public void Execute(Item items, Sitecore.Tasks.CommandItem command, Sitecore.Tasks.ScheduleItem schedule)
A good guide for these can be found here: How To Create A Sitecore Scheduled Task