Beispiel #1
0
        internal GloopContext(HttpContextBase httpContext)
        {
            //This ensures the dispose method is called when the request terminates, though
            // we also ensure this happens in the Umbraco module because the UmbracoContext is added to the
            // http context items.
            httpContext.DisposeOnPipelineCompleted(this);

            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            HttpContext = httpContext;


            var requestUrl = new Uri("http://localhost");
            var request    = GetRequestFromContext();

            if (request != null)
            {
                requestUrl = request.Url;
            }
            OriginalRequestUrl  = requestUrl;
            CleanedGloopUrlPath = UriToGloop(OriginalRequestUrl);
        }
Beispiel #2
0
        // initializes a new instance of the UmbracoContext class
        // internal for unit tests
        // otherwise it's used by EnsureContext above
        // warn: does *not* manage setting any IUmbracoContextAccessor
        internal UmbracoContext(HttpContextBase httpContext,
                                IPublishedSnapshotService publishedSnapshotService,
                                WebSecurity webSecurity,
                                IUmbracoSettingsSection umbracoSettings,
                                IEnumerable <IUrlProvider> urlProviders,
                                IGlobalSettings globalSettings,
                                IVariationContextAccessor variationContextAccessor)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }
            if (publishedSnapshotService == null)
            {
                throw new ArgumentNullException(nameof(publishedSnapshotService));
            }
            if (webSecurity == null)
            {
                throw new ArgumentNullException(nameof(webSecurity));
            }
            if (umbracoSettings == null)
            {
                throw new ArgumentNullException(nameof(umbracoSettings));
            }
            if (urlProviders == null)
            {
                throw new ArgumentNullException(nameof(urlProviders));
            }
            VariationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
            _globalSettings          = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));

            // ensure that this instance is disposed when the request terminates, though we *also* ensure
            // this happens in the Umbraco module since the UmbracoCOntext is added to the HttpContext items.
            //
            // also, it *can* be returned by the container with a PerRequest lifetime, meaning that the
            // container *could* also try to dispose it.
            //
            // all in all, this context may be disposed more than once, but DisposableObject ensures that
            // it is ok and it will be actually disposed only once.
            httpContext.DisposeOnPipelineCompleted(this);

            ObjectCreated    = DateTime.Now;
            UmbracoRequestId = Guid.NewGuid();
            HttpContext      = httpContext;
            Security         = webSecurity;

            // beware - we cannot expect a current user here, so detecting preview mode must be a lazy thing
            _publishedSnapshot = new Lazy <IPublishedSnapshot>(() => publishedSnapshotService.CreatePublishedSnapshot(PreviewToken));

            // set the urls...
            // NOTE: The request will not be available during app startup so we can only set this to an absolute URL of localhost, this
            // is a work around to being able to access the UmbracoContext during application startup and this will also ensure that people
            // 'could' still generate URLs during startup BUT any domain driven URL generation will not work because it is NOT possible to get
            // the current domain during application startup.
            // see: http://issues.umbraco.org/issue/U4-1890
            //
            OriginalRequestUrl = GetRequestFromContext()?.Url ?? new Uri("http://localhost");
            CleanedUmbracoUrl  = UriUtility.UriToUmbraco(OriginalRequestUrl);
            UrlProvider        = new UrlProvider(this, umbracoSettings.WebRouting, urlProviders, variationContextAccessor);
        }
        /// <summary>
        /// Creates a new Umbraco context.
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="applicationContext"> </param>
        /// <param name="publishedCaches">The published caches.</param>
        /// <param name="webSecurity"></param>
        /// <param name="preview">An optional value overriding detection of preview mode.</param>
        internal UmbracoContext(
            HttpContextBase httpContext,
            ApplicationContext applicationContext,
            Lazy <IPublishedCaches> publishedCaches,
            WebSecurity webSecurity,
            bool?preview = null)
        {
            //This ensures the dispose method is called when the request terminates, though
            // we also ensure this happens in the Umbraco module because the UmbracoContext is added to the
            // http context items.
            httpContext.DisposeOnPipelineCompleted(this);

            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            if (applicationContext == null)
            {
                throw new ArgumentNullException("applicationContext");
            }

            ObjectCreated    = DateTime.Now;
            UmbracoRequestId = Guid.NewGuid();

            HttpContext = httpContext;
            Application = applicationContext;
            Security    = webSecurity;

            _contentCache = new Lazy <ContextualPublishedContentCache>(() => publishedCaches.Value.CreateContextualContentCache(this));
            _mediaCache   = new Lazy <ContextualPublishedMediaCache>(() => publishedCaches.Value.CreateContextualMediaCache(this));
            _previewing   = preview;

            // set the urls...
            //original request url
            //NOTE: The request will not be available during app startup so we can only set this to an absolute URL of localhost, this
            // is a work around to being able to access the UmbracoContext during application startup and this will also ensure that people
            // 'could' still generate URLs during startup BUT any domain driven URL generation will not work because it is NOT possible to get
            // the current domain during application startup.
            // see: http://issues.umbraco.org/issue/U4-1890

            var requestUrl = new Uri("http://localhost");
            var request    = GetRequestFromContext();

            if (request != null && request.Url != null)
            {
                requestUrl = request.Url;
            }
            this.OriginalRequestUrl = requestUrl;
            //cleaned request url
            this.CleanedUmbracoUrl = UriUtility.UriToUmbraco(this.OriginalRequestUrl);
        }
Beispiel #4
0
        /// <summary>
        /// Begins to process a request.
        /// </summary>
        /// <param name="httpContext"></param>
        private void BeginRequest(HttpContextBase httpContext)
        {
            // ensure application URL is initialized
            ((RuntimeState)Current.RuntimeState).EnsureApplicationUrl(httpContext.Request);

            // do not process if client-side request
            if (httpContext.Request.Url.IsClientSideRequest())
            {
                return;
            }

            // write the trace output for diagnostics at the end of the request
            httpContext.Trace.Write("UmbracoModule", "Umbraco request begins");

            // ok, process

            // TODO: should we move this to after we've ensured we are processing a routable page?
            // ensure there's an UmbracoContext registered for the current request
            // registers the context reference so its disposed at end of request
            var umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext(httpContext);

            httpContext.DisposeOnPipelineCompleted(umbracoContextReference);
        }
 public override ISubscriptionToken DisposeOnPipelineCompleted(IDisposable target)
 {
     return(_inner.DisposeOnPipelineCompleted(target));
 }