diff --git a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs index 462936c26e..6887163698 100644 --- a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs @@ -7,6 +7,7 @@ using System.Web.Mvc; using System.Web.Routing; using System.Xml; using NUnit.Framework; +using Umbraco.Web.Security; using umbraco.BusinessLogic; using Umbraco.Core; using Umbraco.Core.Models; @@ -402,12 +403,13 @@ namespace Umbraco.Tests.Mvc //PublishedContentCache.UnitTesting = true; // ApplicationContext.Current = new ApplicationContext(false) { IsReady = true }; - var appCtx = new ApplicationContext(false) { IsReady = true }; - + var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper()) { IsReady = true }; + var http = GetHttpContextFactory(url, routeData).HttpContext; var ctx = new UmbracoContext( GetHttpContextFactory(url, routeData).HttpContext, appCtx, - new PublishedCaches(cache, new PublishedMediaCache())); + new PublishedCaches(cache, new PublishedMediaCache()), + new WebSecurity(http, appCtx)); //if (setSingleton) //{ diff --git a/src/Umbraco.Web/Standalone/StandaloneBootManager.cs b/src/Umbraco.Web/Standalone/StandaloneBootManager.cs index d119e4e31c..09d5d5ca10 100644 --- a/src/Umbraco.Web/Standalone/StandaloneBootManager.cs +++ b/src/Umbraco.Web/Standalone/StandaloneBootManager.cs @@ -81,7 +81,7 @@ namespace Umbraco.Web.Standalone base.FreezeResolution(); var httpContext = new StandaloneHttpContext(); - UmbracoContext.EnsureContext(httpContext, ApplicationContext.Current, false, false); + UmbracoContext.EnsureContext(httpContext, ApplicationContext.Current, new WebSecurity(httpContext, ApplicationContext.Current), false, false); } } } diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 7ea0d1fd79..801a554996 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -132,6 +132,38 @@ namespace Umbraco.Web ApplicationContext applicationContext, WebSecurity webSecurity, bool replaceContext) + { + return EnsureContext(httpContext, applicationContext, new WebSecurity(httpContext, applicationContext), replaceContext, null); + } + + /// + /// This is a helper method which is called to ensure that the singleton context is created and the nice url and routing + /// context is created and assigned. + /// + /// + /// + /// + /// + /// if set to true will replace the current singleton with a new one, this is generally only ever used because + /// during application startup the base url domain will not be available so after app startup we'll replace the current + /// context with a new one in which we can access the httpcontext.Request object. + /// + /// + /// + /// The Singleton context object + /// + /// + /// This is created in order to standardize the creation of the singleton. Normally it is created during a request + /// in the UmbracoModule, however this module does not execute during application startup so we need to ensure it + /// during the startup process as well. + /// See: http://issues.umbraco.org/issue/U4-1890, http://issues.umbraco.org/issue/U4-1717 + /// + public static UmbracoContext EnsureContext( + HttpContextBase httpContext, + ApplicationContext applicationContext, + WebSecurity webSecurity, + bool replaceContext, + bool? preview) { if (UmbracoContext.Current != null) { @@ -144,7 +176,8 @@ namespace Umbraco.Web httpContext, applicationContext, PublishedCachesResolver.Current.Caches, - webSecurity); + webSecurity, + preview); // create the nice urls provider // there's one per request because there are some behavior parameters that can be changed