Working with UmbracoHelper and IPublishedContent in HttpHandler

If you were planning to create sitemap.xml in Umbraco, you most probably were doing it with HttpHandler. This was fine until Umbraco version 6.2.2.

If your website was running in lower version, most probably after update your HttpHandler were crashing since UmbracoContext.Current returns null.

However, there is a workaround for this. You need to initialize UmbracoContext on ProcessRequest of your HtppHandler as a first thing.

public void ProcessRequest(HttpContext context) { UmbracoContext.EnsureContext( new HttpContextWrapper(HttpContext.Current), ApplicationContext.Current, true); //The rest of your code }

This simple fix should allow you accessing UmbracoHelper methods and published Umbraco context from App_Data/umbraco.config

Disclaimer

Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.