Example #1
0
        public override void Initialize()
        {
            base.Initialize();

            //the module requires that the singleton is setup
            ApplicationContext.Current = ApplicationContext;

            //create the module
            _module = new UmbracoModule();

            ConfigurationManager.AppSettings.Set("umbracoConfigurationStatus", Umbraco.Core.Configuration.GlobalSettings.CurrentVersion);
            ConfigurationManager.AppSettings.Set("umbracoReservedPaths", "~/umbraco,~/install/");
            ConfigurationManager.AppSettings.Set("umbracoReservedUrls", "~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd");

            //create the not found handlers config
            using (var sw = File.CreateText(Umbraco.Core.IO.IOHelper.MapPath(Umbraco.Core.IO.SystemFiles.NotFoundhandlersConfig, false)))
            {
                sw.Write(@"<NotFoundHandlers>
	<notFound assembly='umbraco' type='SearchForAlias' />
	<notFound assembly='umbraco' type='SearchForTemplate'/>
	<notFound assembly='umbraco' type='SearchForProfile'/>
	<notFound assembly='umbraco' type='handle404'/>
</NotFoundHandlers>");
            }
        }
Example #2
0
        public override void Initialize()
        {
            base.Initialize();

            //create the module
            _module = new UmbracoModule();

            SettingsForTests.ConfigurationStatus = UmbracoVersion.Current.ToString(3);
            //SettingsForTests.ReservedPaths = "~/umbraco,~/install/";
            //SettingsForTests.ReservedUrls = "~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd";

            //create the not found handlers config
            using (var sw = File.CreateText(Umbraco.Core.IO.IOHelper.MapPath(Umbraco.Core.IO.SystemFiles.NotFoundhandlersConfig, false)))
            {
                sw.Write(@"<NotFoundHandlers>
	<notFound assembly='umbraco' type='SearchForAlias' />
	<notFound assembly='umbraco' type='SearchForTemplate'/>
	<notFound assembly='umbraco' type='SearchForProfile'/>
	<notFound assembly='umbraco' type='handle404'/>
</NotFoundHandlers>");
            }
        }
Example #3
0
        /// <summary>
        /// this will determine the controller and set the values in the route data
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="request"></param>
        internal IHttpHandler GetHandlerForRoute(RequestContext requestContext, PublishedRequest request)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException(nameof(requestContext));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var routeDef = GetUmbracoRouteDefinition(requestContext, request);

            //Need to check for a special case if there is form data being posted back to an Umbraco URL
            var postedInfo = GetFormInfo(requestContext);

            if (postedInfo != null)
            {
                return(HandlePostedValues(requestContext, postedInfo));
            }


            //Here we need to check if there is no hijacked route and no template assigned,
            //if this is the case we want to return a blank page, but we'll leave that up to the NoTemplateHandler.
            //We also check if templates have been disabled since if they are then we're allowed to render even though there's no template,
            //for example for json rendering in headless.
            if ((request.HasTemplate == false && Features.Disabled.DisableTemplates == false) &&
                routeDef.HasHijackedRoute == false)
            {
                request.UpdateToNotFound(); // request will go 404

                // HandleHttpResponseStatus returns a value indicating that the request should
                // not be processed any further, eg because it has been redirect. then, exit.
                if (UmbracoModule.HandleHttpResponseStatus(requestContext.HttpContext, request, Current.Logger))
                {
                    return(null);
                }

                var handler = GetHandlerOnMissingTemplate(request);

                // if it's not null it's the PublishedContentNotFoundHandler (no document was found to handle 404, or document with no template was found)
                // if it's null it means that a document was found

                // if we have a handler, return now
                if (handler != null)
                {
                    return(handler);
                }

                // else we are running Mvc
                // update the route data - because the PublishedContent has changed
                UpdateRouteDataForRequest(
                    new ContentModel(request.PublishedContent),
                    requestContext);
                // update the route definition
                routeDef = GetUmbracoRouteDefinition(requestContext, request);
            }

            //no post values, just route to the controller/action required (local)

            requestContext.RouteData.Values["controller"] = routeDef.ControllerName;
            if (string.IsNullOrWhiteSpace(routeDef.ActionName) == false)
            {
                requestContext.RouteData.Values["action"] = routeDef.ActionName;
            }

            // Set the session state requirements
            requestContext.HttpContext.SetSessionStateBehavior(GetSessionStateBehavior(requestContext, routeDef.ControllerName));

            // reset the friendly path so in the controllers and anything occurring after this point in time,
            //the URL is reset back to the original request.
            requestContext.HttpContext.RewritePath(UmbracoContext.OriginalRequestUrl.PathAndQuery);

            return(new UmbracoMvcHandler(requestContext));
        }
Example #4
0
        /// <summary>
        /// this will determine the controller and set the values in the route data
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="publishedContentRequest"></param>
        internal IHttpHandler GetHandlerForRoute(RequestContext requestContext, PublishedContentRequest publishedContentRequest)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }
            if (publishedContentRequest == null)
            {
                throw new ArgumentNullException("publishedContentRequest");
            }

            var routeDef = GetUmbracoRouteDefinition(requestContext, publishedContentRequest);

            //Need to check for a special case if there is form data being posted back to an Umbraco URL
            var postedInfo = GetFormInfo(requestContext);

            if (postedInfo != null)
            {
                return(HandlePostedValues(requestContext, postedInfo));
            }

            //here we need to check if there is no hijacked route and no template assigned, if this is the case
            //we want to return a blank page, but we'll leave that up to the NoTemplateHandler.
            if (!publishedContentRequest.HasTemplate && !routeDef.HasHijackedRoute)
            {
                publishedContentRequest.UpdateOnMissingTemplate();                 // will go 404

                // HandleHttpResponseStatus returns a value indicating that the request should
                // not be processed any further, eg because it has been redirect. then, exit.
                if (UmbracoModule.HandleHttpResponseStatus(requestContext.HttpContext, publishedContentRequest))
                {
                    return(null);
                }

                var handler = GetHandlerOnMissingTemplate(publishedContentRequest);

                // if it's not null it can be either the PublishedContentNotFoundHandler (no document was
                // found to handle 404, or document with no template was found) or the WebForms handler
                // (a document was found and its template is WebForms)

                // if it's null it means that a document was found and its template is Mvc

                // if we have a handler, return now
                if (handler != null)
                {
                    return(handler);
                }

                // else we are running Mvc
                // update the route data - because the PublishedContent has changed
                UpdateRouteDataForRequest(
                    new RenderModel(publishedContentRequest.PublishedContent, publishedContentRequest.Culture),
                    requestContext);
                // update the route definition
                routeDef = GetUmbracoRouteDefinition(requestContext, publishedContentRequest);
            }

            //no post values, just route to the controller/action requried (local)

            requestContext.RouteData.Values["controller"] = routeDef.ControllerName;
            if (!string.IsNullOrWhiteSpace(routeDef.ActionName))
            {
                requestContext.RouteData.Values["action"] = routeDef.ActionName;
            }

            // Set the session state requirements
            requestContext.HttpContext.SetSessionStateBehavior(GetSessionStateBehavior(requestContext, routeDef.ControllerName));

            // reset the friendly path so in the controllers and anything occuring after this point in time,
            //the URL is reset back to the original request.
            requestContext.HttpContext.RewritePath(UmbracoContext.OriginalRequestUrl.PathAndQuery);

            return(new UmbracoMvcHandler(requestContext));
        }