Ejemplo n.º 1
0
        public virtual ActionResult DynamicPreview()
        {
            CMSPageDynamicPreviewRequest dynamicPreviewRequest;

            //dynamic preview can only be done one at a time, since they share the same navigation builder, which needs the pub target context
            //multi-thread it will cause mix up of urls from different pub targets
            dynamicPreviewRequest = _PageFactory.GetDynamicPreviewPage(Request, false) as CMSPageDynamicPreviewRequest;

            //no caching for preview
            disableClientSideCaching();

            if (dynamicPreviewRequest.IsComponent ||
                _AllowTfrm && (dynamicPreviewRequest.TransformOption == TransformOptions.ExpansionOnly ||
                               dynamicPreviewRequest.TransformOption == TransformOptions.Raw))
            {
                return(new XmlResult(dynamicPreviewRequest.ContentDocument));
            }
            else if (dynamicPreviewRequest.TransformOption == TransformOptions.Default)
            {
                return(viewOrXsltFallback(dynamicPreviewRequest));
            }
            else
            {
                return(new PreviewXsltTransformResult(dynamicPreviewRequest, _SitePath, false));
            }
        }
Ejemplo n.º 2
0
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            if (string.IsNullOrWhiteSpace(_BaseController))
            {
                _BaseController = ConfigurationManager.AppSettings["BaseControllerName"]
                                  .ToNullOrEmptyHelper()
                                  .Return(DEFAULT_CONTROLLER_NAME);
            }

            ICMSRequest pageRequest = null;
            RouteData   data        = null;
            string      action      = defaultAction;
            string      controller  = _BaseController;

            string appPath = httpContext.Request.ApplicationPath;

            if (appPath == "/")
            {
                appPath = string.Empty;
            }

            string relativePath = httpContext.Request.Path.Substring(appPath.Length).ToLowerInvariant();

            if (relativePath.StartsWith("/igxdtpreview"))
            {
                pageRequest = _PageFactory.GetPreviewPage(httpContext.Request, true);
                // because the preview does not get a url, but rather an id and xml,
                // it is not possible to look for other actions based on the URL
                action = "Preview";
                locateController(pageRequest, ref controller);
                data = createRouteData(action, controller);
            }
            if (relativePath.StartsWith("/igxdynamicpreview") || _PageFactory == null)
            {
                action = "DynamicPreview";
                try
                {
                    CMS.IContentStore contentStore = CMSPageFactoryHelper.GetPreviewContentStore(httpContext.Request.RequestContext, _SitePath);
                    CMS.IReadonlyUser currentUser  = CMSPageFactoryHelper.GetPreviewCurrentUser(contentStore,
                                                                                                httpContext.Request.RequestContext, httpContext.Session);

                    _PageFactory = new DocumentPreviewPageFactory(contentStore, currentUser, _SitePath);
                    _PageFactory.CacheSiteControls = false;

                    pageRequest = _PageFactory.GetDynamicPreviewPage(httpContext.Request, true, true);
                    // because the preview does not get a url, but rather an id and xml,
                    // it is not possible to look for other actions based on the URL

                    locateController(pageRequest, ref controller);
                }
                catch
                {
                    controller = "CMSPageDefault";
                }
                data = createRouteData(action, controller);
            }
            else
            {
                //only need the schema data, not the whole page
                ICMSRoutingRequest routingRequest = _PageFactory.GetPage(httpContext.Request, true);
                if (routingRequest != null && routingRequest.CMSRequest != null && routingRequest.CMSRequest.Exists)
                {
                    pageRequest = routingRequest.CMSRequest;
                    if (pageRequest != null)
                    {
                        //use default controller for routing request
                        if (pageRequest is CMSPageRedirectRequest)
                        {
                            data = createRouteData(defaultAction, controller);
                        }
                        else
                        {
                            var matchingController = locateController(pageRequest, ref controller);

                            if (!string.IsNullOrEmpty(routingRequest.RemaingPath.Trim('/')))
                            {
                                //use the first section of the remaining path as action, this is arbitrary.
                                string actionInPath = routingRequest.RemaingPath.Trim('/').SubstringBefore("/");

                                //if the controller doesn't have this action, use default action
                                action = matchingController.ToNullHelper()
                                         .Propagate(
                                    c => c.ActionNames
                                    .Where(an => an.ToLowerInvariant() == actionInPath.ToLowerInvariant())
                                    .FirstOrDefault())
                                         .Return(defaultAction);

                                //get the remaining path in the controller action itself
                            }
                            else
                            {
                                action = defaultAction;
                            }

                            data = createRouteData(action, controller);
                        }
                    }
                    else
                    {
                        data = createRouteData(defaultAction, controller);
                    }
                }
                else
                {
                    data = createRouteData(defaultAction, controller);
                }
            }

            return(data);
        }