Skip to content

Instantly share code, notes, and snippets.

View TorbenRahbekKoch's full-sized avatar

Torben Koch Pløen TorbenRahbekKoch

View GitHub Profile
@sniffdk
sniffdk / ContextHelpers.cs
Last active February 28, 2022 10:03
Fake an UmbracoContext for use when doing published scheduling or other scenarios where UmbracoContext is normally null.
public class ContextHelpers
{
public static UmbracoContext EnsureUmbracoContext() {
if (UmbracoContext.Current != null)
{
return UmbracoContext.Current;
}
var httpContext = new HttpContextWrapper(HttpContext.Current ?? new HttpContext(new SimpleWorkerRequest("temp.aspx", "", new StringWriter())));