예제 #1
0
        private void ProcessOutputCache(RequestContext requestContext)
        {
            if (HttpContext.Current == null)
            {
                return;
            }

            var user = requestContext.HttpContext.User;

            if (user == null || user.Identity.IsAuthenticated)
            {
                return;
            }

            ICacheManager cacheManager = RouteExtensions.ResolveService <ICacheManager>(requestContext.RouteData);

            if (adhereToConfig && !cacheManager.Enabled)
            {
                return;
            }

            var page = new OutputCachedPage(cacheManager.GetOutputCacheParameters());

            page.ProcessRequest(HttpContext.Current);
            cacheManager.AddCacheInvalidation(HttpContext.Current.Response);
        }
예제 #2
0
        public static void InitTheme(this ControllerContext context)
        {
            var page = context.RequestContext.CurrentPage <ContentItem>()
                       ?? RouteExtensions.ResolveService <IUrlParser>(context.RouteData).FindPath(context.HttpContext.Request["returnUrl"]).StopItem
                       ?? RouteExtensions.ResolveService <IUrlParser>(context.RouteData).FindPath(context.HttpContext.Request.AppRelativeCurrentExecutionFilePath).StopItem
                       ?? context.RequestContext.StartPage();

            InitTheme(context, page);
        }
예제 #3
0
        internal static T CurrentItem <T>(this RequestContext context, string key) where T : ContentItem
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            return(context.RouteData.DataTokens[key] as T
                   ?? context.RouteData.Values.CurrentItem <T>(key, RouteExtensions.GetEngine(context.RouteData).Persister));
        }
        private ControllerContext BuildPageControllerContext(ControllerContext context)
        {
            string controllerName = controllerMapper.GetControllerName(thePage.GetContentType());

            RouteExtensions.ApplyCurrentPath(context.RouteData, controllerName, "Index", new PathData(thePage));

            var requestContext = new RequestContext(context.HttpContext, context.RouteData);

            var controller = (ControllerBase)controllerFactory.CreateController(requestContext, controllerName);

            controller.ControllerContext = new ControllerContext(requestContext, controller);
            controller.ViewData.ModelState.Merge(context.Controller.ViewData.ModelState);

            return(controller.ControllerContext);
        }
예제 #5
0
 protected virtual void SetPathOverride(ActionExecutingContext filterContext)
 {
     if (content == null &&
         ControllerContext != null &&
         ControllerContext.IsChildAction &&
         ControllerContext.ParentActionViewContext != null &&
         ControllerContext.ParentActionViewContext.RouteData.DataTokens.ContainsKey(PathOverrideKey))
     {
         //  bypass normal retrieval to handle rendering of auto-generated parts wihtout ID
         var path = ControllerContext.ParentActionViewContext.RouteData.DataTokens[PathOverrideKey] as PathData;
         if (path != null)
         {
             content = new ControllerContentHelper(() => RouteExtensions.GetEngine(RouteData), () => path);
         }
     }
 }
예제 #6
0
        private ControllerContext BuildPageControllerContext(ControllerContext context)
        {
            string controllerName = _controllerMapper.GetControllerName(_thePage.GetContentType());

            var routeData = context.RouteData;

            RouteExtensions.ApplyCurrentItem(routeData, controllerName, "Index", _thePage, null);
            if (context.RouteData.DataTokens.ContainsKey(ContentRoute.ContentPartKey))
            {
                routeData.ApplyContentItem(ContentRoute.ContentPartKey, context.RouteData.DataTokens[ContentRoute.ContentPartKey] as ContentItem);
            }

            var requestContext = new RequestContext(context.HttpContext, routeData);

            var controller = (ControllerBase)ControllerBuilder.Current.GetControllerFactory()
                             .CreateController(requestContext, controllerName);

            controller.ControllerContext = new ControllerContext(requestContext, controller);
            controller.ViewData.ModelState.Merge(context.Controller.ViewData.ModelState);

            return(controller.ControllerContext);
        }
예제 #7
0
        private RouteData GetRouteDataForPath(HttpRequestBase request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (request.Url == null)
            {
                throw new ArgumentException("Request has no URL", "request");
            }

            //On a multi-lingual site with separate domains per language,
            //the full url (with host) should be passed to UrlParser.ResolvePath():
            string   host = (request.Url.IsDefaultPort) ? request.Url.Host : request.Url.Authority;
            var      url  = new Url(request.Url.Scheme, host, request.RawUrl);
            PathData path;
            var      rpp = engine.Resolve <RequestPathProvider>();

            if (rpp.IsRewritable(url) && rpp.IsObservable(url))
            {
                path = rpp.ResolveUrl(url);
            }
            else
            {
                path = PathData.Empty;
            }

            if (!path.IsEmpty() && path.IsRewritable && StopRewritableItems)
            {
                return(new RouteData(this, new StopRoutingHandler()));
            }

            var page = path.CurrentPage;

            var actionName = path.Action;

            if (string.IsNullOrEmpty(actionName))
            {
                actionName = request.QueryString["action"] ?? "Index";
            }

            if (!string.IsNullOrEmpty(request.QueryString[PathData.PageQueryKey]))
            {
                int pageId;
                if (int.TryParse(request.QueryString[PathData.PageQueryKey], out pageId))
                {
                    path.CurrentPage = page = engine.Persister.Get(pageId);
                }
            }

            ContentItem part = null;

            if (!string.IsNullOrEmpty(request.QueryString[PathData.PartQueryKey]))
            {
                // part in query string is used to render a part
                int partId;
                if (int.TryParse(request.QueryString[PathData.PartQueryKey], out partId))
                {
                    path.CurrentItem = part = engine.Persister.Get(partId);
                    path.Controller  = null;
                }
            }
            else if (!string.IsNullOrEmpty(request.QueryString[PathData.ItemQueryKey]))
            {
                // this is a discrepancy between mvc and the legacy
                // in mvc the item query key doesn't route to the item, it's a marker
                // the urlparser however parses the item query key and passes the item as current in pathdata
                // hence this somewhat strange sidestepping
                int itemId;
                if (int.TryParse(request.QueryString[PathData.ItemQueryKey], out itemId))
                {
                    if (itemId == path.ID || (path.ID == 0 && path.CurrentItem != null && itemId == path.CurrentItem.VersionOf.ID))
                    {
                        // we have an item id and it matches the path data we found via url parser
                        // it hasn't been changed by a specific part query string so we reset it
                        path.CurrentItem = path.CurrentPage;
                        path.Controller  = null;
                    }
                }
            }

            if (page == null && part == null)
            {
                return(null);
            }

            path.CurrentPage = page ?? part.ClosestPage();

            var controllerName = path.Controller
                                 ?? controllerMapper.GetControllerName((part ?? page).GetContentType());

            if (controllerName == null)
            {
                return(null);
            }

            if (actionName == null || !controllerMapper.ControllerHasAction(controllerName, actionName))
            {
                return(null);
            }

            var data = new RouteData(this, routeHandler);

            foreach (var defaultPair in innerRoute.Defaults)
            {
                data.Values[defaultPair.Key] = defaultPair.Value;
            }
            foreach (var tokenPair in innerRoute.DataTokens)
            {
                data.DataTokens[tokenPair.Key] = tokenPair.Value;
            }

            RouteExtensions.ApplyCurrentPath(data, controllerName, actionName, path);
            data.DataTokens[ContentEngineKey] = engine;

            return(data);
        }
예제 #8
0
        private RouteData GetRouteDataForPath(HttpRequestBase request)
        {
            //On a multi-lingual site with separate domains per language,
            //the full url (with host) should be passed to UrlParser.ResolvePath():
            string   host = (request.Url.IsDefaultPort) ? request.Url.Host : request.Url.Authority;
            var      url  = new Url(request.Url.Scheme, host, request.AppRelativeCurrentExecutionFilePath);
            PathData td   = engine.Resolve <RequestPathProvider>().ResolveUrl(url);

            var page = td.CurrentPage;

            var actionName = td.Action;

            if (string.IsNullOrEmpty(actionName))
            {
                actionName = request.QueryString["action"] ?? "Index";
            }

            if (!string.IsNullOrEmpty(request.QueryString[PathData.PageQueryKey]))
            {
                int pageId;
                if (int.TryParse(request.QueryString[PathData.PageQueryKey], out pageId))
                {
                    td.CurrentPage = page = engine.Persister.Get(pageId);
                }
            }

            ContentItem part = null;

            if (!string.IsNullOrEmpty(request.QueryString[PathData.PartQueryKey]))
            {
                // part in query string is used to render a part
                int partId;
                if (int.TryParse(request.QueryString[PathData.PartQueryKey], out partId))
                {
                    td.CurrentItem = part = engine.Persister.Get(partId);
                }
            }

            if (page == null && part == null)
            {
                return(null);
            }
            else if (page == null)
            {
                page = part.ClosestPage();
            }

            var controllerName = controllerMapper.GetControllerName((part ?? page).GetContentType());

            if (controllerName == null)
            {
                return(null);
            }

            if (actionName == null || !controllerMapper.ControllerHasAction(controllerName, actionName))
            {
                return(null);
            }

            var data = new RouteData(this, routeHandler);

            foreach (var defaultPair in innerRoute.Defaults)
            {
                data.Values[defaultPair.Key] = defaultPair.Value;
            }
            foreach (var tokenPair in innerRoute.DataTokens)
            {
                data.DataTokens[tokenPair.Key] = tokenPair.Value;
            }

            RouteExtensions.ApplyCurrentItem(data, controllerName, actionName, page, part);
            data.DataTokens[ContentEngineKey] = engine;

            return(data);
        }
예제 #9
0
 public static ContentItem StartPage(this RequestContext context)
 {
     return(Find.ClosestOf <IStartPage>(context.RouteData.CurrentPath().CurrentItem)
            ?? RouteExtensions.GetEngine(context.RouteData).Content.Traverse.StartPage);
 }