From 67e3ec2ae0670dc0dc63856856f5b5f2a6fee643 Mon Sep 17 00:00:00 2001 From: Tom Pipe Date: Mon, 24 Apr 2017 13:23:12 +0100 Subject: [PATCH] Quick/simple fix for the stale variable The umbracoContext variable can hold a null reference to UmbracoContext.Current. If a request containing a file extension is passed through an UmbracoVirtualNodeRouteHandler, the UmbracoContext will be null, because a context is never created for urls containing extensions due to https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Core/UriExtensions.cs#L143 A call can be made to EnsureContext in the overridden FindContent method, but the fresh context would never get picked up, instead the variable always contains a null reference, and an exception is then thrown on line 23 --- src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs index 5c948d2e0b..3f919f4355 100644 --- a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs @@ -15,11 +15,11 @@ namespace Umbraco.Web.Mvc { public IHttpHandler GetHttpHandler(RequestContext requestContext) { - var umbracoContext = UmbracoContext.Current; - - var found = FindContent(requestContext, umbracoContext); + var found = FindContent(requestContext, UmbracoContext.Current); if (found == null) return new NotFoundHandler(); + var umbracoContext = UmbracoContext.Current; + umbracoContext.PublishedContentRequest = new PublishedContentRequest( umbracoContext.CleanedUmbracoUrl, umbracoContext.RoutingContext, UmbracoConfig.For.UmbracoSettings().WebRouting, s => Roles.Provider.GetRolesForUser(s))