Ejemplo n.º 1
0
 /// <summary>
 /// 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.
 /// </summary>
 /// <param name="httpContext"></param>
 /// <param name="applicationContext"></param>
 /// <param name="webSecurity"></param>
 /// <returns>
 /// The Singleton context object
 /// </returns>
 /// <remarks>
 /// 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
 /// </remarks>
 public static UmbracoContext EnsureContext(
     HttpContextBase httpContext,
     ApplicationContext applicationContext,
     WebSecurity webSecurity)
 {
     return EnsureContext(httpContext, applicationContext, webSecurity, false);
 }
 public MediaPostValidateAttribute(IMediaService mediaService, WebSecurity security)
 {
     if (mediaService == null) throw new ArgumentNullException("mediaService");
     if (security == null) throw new ArgumentNullException("security");
     _mediaService = mediaService;
     _security = security;
 }
 public ContentPostValidateAttribute(IContentService contentService, IUserService userService, WebSecurity security)
 {
     if (contentService == null) throw new ArgumentNullException("contentService");
     if (userService == null) throw new ArgumentNullException("userService");
     if (security == null) throw new ArgumentNullException("security");
     _contentService = contentService;
     _userService = userService;
     _security = security;
 }
Ejemplo n.º 4
0
        /// <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,
            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 = publishedCaches.CreateContextualContentCache(this);
            MediaCache = publishedCaches.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)
            {
                requestUrl = request.Url;
            }
            this.OriginalRequestUrl = requestUrl;
            //cleaned request url
            this.CleanedUmbracoUrl = UriUtility.UriToUmbraco(this.OriginalRequestUrl);

        } 
Ejemplo n.º 5
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="applicationContext"></param>
        /// <param name="webSecurity"></param>
        /// <param name="replaceContext">
        /// 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.
        /// </param>
        /// <param name="preview"></param>
        /// <returns>
        /// The Singleton context object
        /// </returns>
        /// <remarks>
        /// 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
        /// </remarks>
        public static UmbracoContext EnsureContext(
            HttpContextBase httpContext,
            ApplicationContext applicationContext,
            WebSecurity webSecurity,
            bool replaceContext,
            bool? preview)
        {
            if (UmbracoContext.Current != null)
            {
                if (!replaceContext)
                    return UmbracoContext.Current;
                UmbracoContext.Current._replacing = true;
            }

            var umbracoContext = new UmbracoContext(
                httpContext,
                applicationContext,
                PublishedCachesResolver.Current.Caches,
                webSecurity,
                preview);

            // create the nice urls provider
            // there's one per request because there are some behavior parameters that can be changed
            var urlProvider = new UrlProvider(
                umbracoContext,
                UrlProviderResolver.Current.Providers);

            // create the RoutingContext, and assign
            var routingContext = new RoutingContext(
                umbracoContext,
                ContentFinderResolver.Current.Finders,
                ContentLastChanceFinderResolver.Current.Finder,
                urlProvider);

            //assign the routing context back
            umbracoContext.RoutingContext = routingContext;

            //assign the singleton
            UmbracoContext.Current = umbracoContext;
            return UmbracoContext.Current;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 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.
 /// </summary>
 /// <param name="httpContext"></param>
 /// <param name="applicationContext"></param>
 /// <param name="webSecurity"></param>
 /// <param name="replaceContext">
 /// 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.
 /// </param>
 /// <returns>
 /// The Singleton context object
 /// </returns>
 /// <remarks>
 /// 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
 /// </remarks>
 public static UmbracoContext EnsureContext(
     HttpContextBase httpContext,
     ApplicationContext applicationContext,
     WebSecurity webSecurity,
     bool replaceContext)
 {
     return EnsureContext(httpContext, applicationContext, new WebSecurity(httpContext, applicationContext), replaceContext, null);
 }