From 7d8ec2678cd8d451572480fde20335d3099e1844 Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 24 Sep 2012 12:49:36 -0200 Subject: [PATCH] initialize Umbraco sooner in the request pipeline --- src/Umbraco.Web/LegacyRequestInitializer.cs | 2 ++ src/Umbraco.Web/UmbracoModule.cs | 39 ++++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Web/LegacyRequestInitializer.cs b/src/Umbraco.Web/LegacyRequestInitializer.cs index a89e55c054..0621520d5b 100644 --- a/src/Umbraco.Web/LegacyRequestInitializer.cs +++ b/src/Umbraco.Web/LegacyRequestInitializer.cs @@ -21,6 +21,8 @@ namespace Umbraco.Web { var uri = _requestUrl; + global::umbraco.presentation.UmbracoContext.Current = new global::umbraco.presentation.UmbracoContext(_httpContext); + // legacy - umbOriginalUrl used by default.aspx to rewritepath so forms are happy // legacy - umbOriginalUrl used by presentation/umbraco/urlRewriter/UrlRewriterFormWriter which handles
- /// Processses the Umbraco Request + /// Begins to process a request. /// /// - void ProcessRequest(HttpContextBase httpContext) + void BeginRequest(HttpContextBase httpContext) { if (IsClientSideRequest(httpContext.Request.Url)) - { return; - } - //create the legacy UmbracoContext - global::umbraco.presentation.UmbracoContext.Current = new global::umbraco.presentation.UmbracoContext(httpContext); - - //create the LegacyRequestInitializer + // create the LegacyRequestInitializer + // and initialize legacy stuff var legacyRequestInitializer = new LegacyRequestInitializer(httpContext.Request.Url, httpContext); - // legacy - initialize legacy stuff legacyRequestInitializer.InitializeRequest(); - //create the UmbracoContext singleton, one per request!! + // create the UmbracoContext singleton, one per request, and assign var umbracoContext = new UmbracoContext( httpContext, ApplicationContext.Current, RoutesCacheResolver.Current.RoutesCache); UmbracoContext.Current = umbracoContext; - //create the nice urls + // create the nice urls provider var niceUrls = new NiceUrlProvider(PublishedContentStoreResolver.Current.PublishedContentStore, umbracoContext); - //create the RoutingContext + + // create the RoutingContext, and assign var routingContext = new RoutingContext( umbracoContext, DocumentLookupsResolver.Current.DocumentLookups, LastChanceLookupResolver.Current.LastChanceLookup, PublishedContentStoreResolver.Current.PublishedContentStore, niceUrls); - //assign the routing context back to the umbraco context umbracoContext.RoutingContext = routingContext; + } + + /// + /// Processses the Umbraco Request + /// + /// + void ProcessRequest(HttpContextBase httpContext) + { + if (IsClientSideRequest(httpContext.Request.Url)) + return; + + var umbracoContext = UmbracoContext.Current; + var routingContext = umbracoContext.RoutingContext; // remap to handler if it is a base rest request if (BaseRest.BaseRestHandler.IsBaseRestRequest(umbracoContext.RequestUrl)) @@ -407,6 +415,11 @@ namespace Umbraco.Web /// public void Init(HttpApplication app) { + app.BeginRequest += (sender, e) => + { + var httpContext = ((HttpApplication)sender).Context; + BeginRequest(new HttpContextWrapper(httpContext)); + }; app.PostResolveRequestCache += (sender, e) => {