Esempio n. 1
0
        /// <summary>
        /// Execute an 'im mem' preview request of the provided page and content. The execution depends on the hosting environment.
        /// Then running in pipeline mode the current HttpContext is 
        /// </summary>
        /// <param name="selectedPage">Page to render. Functionality reading the rendered page ID will get the ID from this object.</param>
        /// <param name="contents">Content to render on the page</param>
        /// <param name="renderingReason">The rendering reason</param>
        /// <returns>The page html as a string when running in classic mode. In Pipeline mode the content is written directly to the HttpContext and an empty string is returned.</returns>
        public static string RenderPreview(IPage selectedPage, IList<IPagePlaceholderContent> contents, RenderingReason renderingReason)
        {
            HttpContext ctx = HttpContext.Current;
            string key = Guid.NewGuid().ToString();
            string query = "previewKey=" + key;

            ctx.Cache.Add(key + "_SelectedPage", selectedPage, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
            ctx.Cache.Add(key + "_SelectedContents", contents, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
            ctx.Cache.Add(key + "_RenderingReason", renderingReason, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);

            if (HttpRuntime.UsingIntegratedPipeline)
            {
                // The header trick here is to work around (what seems to be) a bug in .net 4.5, where preserveForm=false is ignored
                // asp.net 4.5 request validation will see the 'page edit http post' data and start bitching. It really should not.
                var headers = new System.Collections.Specialized.NameValueCollection();
                headers.Add("Content-Length", "0");

                string cookieHeader = ctx.Request.Headers["Cookie"];
                if (!string.IsNullOrEmpty(cookieHeader))
                {
                    headers.Add("Cookie", cookieHeader);
                }

                ctx.Server.TransferRequest("~/Renderers/Page.aspx?" + query, false, "GET", headers);
            }
            else
            {
                var sb = new StringBuilder();
                var writer = new StringWriter(sb);

                var wr = new PreviewWorkerRequest(query, ctx, writer);

                AllowChildRequestSessionAccess(ctx);
                HttpRuntime.ProcessRequest(wr);

                // Preview <iframe /> has source "~/Composite/content/flow/FlowUi.aspx" and page is rendered from "~/Renderers/Page.aspx"
                // The following line fixes style references processed by ASP.NET-s Control.ResolveClientUrl()
                sb = sb.Replace("href=\"../", "href=\"../../../");

                return sb.ToString();
            }

            return String.Empty;
        }
        /// <summary>
        /// Execute an 'im mem' preview request of the provided page and content. Requires IIS to run in "Integrated" pipeline mode.
        /// </summary>
        /// <param name="selectedPage">Page to render. Functionality reading the rendered page ID will get the ID from this object.</param>
        /// <param name="contents">Content to render on the page</param>
        /// <param name="renderingReason">The rendering reason</param>
        /// <returns>
        /// In Pipeline mode the content is written directly to the HttpContext and an empty string is returned.
        /// The IIS classic mode is no longer supported and will throw an exception.
        /// </returns>
        public static string RenderPreview(IPage selectedPage, IList <IPagePlaceholderContent> contents, RenderingReason renderingReason)
        {
            HttpContext ctx   = HttpContext.Current;
            string      key   = Guid.NewGuid().ToString();
            string      query = "previewKey=" + key;

            ctx.Cache.Add(key + "_SelectedPage", selectedPage, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
            ctx.Cache.Add(key + "_SelectedContents", contents, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
            ctx.Cache.Add(key + "_RenderingReason", renderingReason, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);

            if (!HttpRuntime.UsingIntegratedPipeline)
            {
                throw new InvalidOperationException("IIS classic mode not supported");
            }

            // The header trick here is to work around (what seems to be) a bug in .net 4.5, where preserveForm=false is ignored
            // asp.net 4.5 request validation will see the 'page edit http post' data and start bitching. It really should not.
            var headers = new System.Collections.Specialized.NameValueCollection
            {
                { "Content-Length", "0" }
            };

            string cookieHeader = ctx.Request.Headers["Cookie"];

            if (!string.IsNullOrEmpty(cookieHeader))
            {
                headers.Add("Cookie", cookieHeader);
            }

            ctx.Server.TransferRequest("~/Renderers/Page.aspx?" + query, false, "GET", headers);

            return(String.Empty);
        }
 public C1RenderingReasonAttribute(RenderingReason renderingReason)
 {
     _renderingReason = renderingReason;
 }
 public RenderingReasonAttribute(RenderingReason renderingReason)
 {
     _renderingReason = renderingReason;
 }
Esempio n. 5
0
        /// <summary>
        /// Execute an 'im mem' preview request of the provided page and content. The execution depends on the hosting environment.
        /// Then running in pipeline mode the current HttpContext is
        /// </summary>
        /// <param name="selectedPage">Page to render. Functionality reading the rendered page ID will get the ID from this object.</param>
        /// <param name="contents">Content to render on the page</param>
        /// <param name="renderingReason">The rendering reason</param>
        /// <returns>The page html as a string when running in classic mode. In Pipeline mode the content is written directly to the HttpContext and an empty string is returned.</returns>
        public static string RenderPreview(IPage selectedPage, IList <IPagePlaceholderContent> contents, RenderingReason renderingReason)
        {
            HttpContext ctx   = HttpContext.Current;
            string      key   = Guid.NewGuid().ToString();
            string      query = "previewKey=" + key;

            ctx.Cache.Add(key + "_SelectedPage", selectedPage, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
            ctx.Cache.Add(key + "_SelectedContents", contents, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
            ctx.Cache.Add(key + "_RenderingReason", renderingReason, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);

            if (HttpRuntime.UsingIntegratedPipeline)
            {
                // The header trick here is to work around (what seems to be) a bug in .net 4.5, where preserveForm=false is ignored
                // asp.net 4.5 request validation will see the 'page edit http post' data and start bitching. It really should not.
                var headers = new System.Collections.Specialized.NameValueCollection();
                headers.Add("Content-Length", "0");

                string cookieHeader = ctx.Request.Headers["Cookie"];
                if (!string.IsNullOrEmpty(cookieHeader))
                {
                    headers.Add("Cookie", cookieHeader);
                }

                ctx.Server.TransferRequest("~/Renderers/Page.aspx?" + query, false, "GET", headers);
            }
            else
            {
                var sb     = new StringBuilder();
                var writer = new StringWriter(sb);

                var wr = new PreviewWorkerRequest(query, ctx, writer);

                AllowChildRequestSessionAccess(ctx);
                HttpRuntime.ProcessRequest(wr);

                // Preview <iframe /> has source "~/Composite/content/flow/FlowUi.aspx" and page is rendered from "~/Renderers/Page.aspx"
                // The following line fixes style references processed by ASP.NET-s Control.ResolveClientUrl()
                sb = sb.Replace("href=\"../", "href=\"../../../");

                return(sb.ToString());
            }

            return(String.Empty);
        }
Esempio n. 6
0
        /// <summary>
        /// Execute an 'im mem' preview request of the provided page and content. Requires IIS to run in "Integrated" pipeline mode.
        /// </summary>
        /// <param name="selectedPage">Page to render. Functionality reading the rendered page ID will get the ID from this object.</param>
        /// <param name="contents">Content to render on the page</param>
        /// <param name="renderingReason">The rendering reason</param>
        /// <returns>
        /// In Pipeline mode the content is written directly to the HttpContext and an empty string is returned.
        /// The IIS classic mode is no longer supported and will throw an exception.
        /// </returns>
        public static string RenderPreview(IPage selectedPage, IList <IPagePlaceholderContent> contents, RenderingReason renderingReason)
        {
            if (!HttpRuntime.UsingIntegratedPipeline)
            {
                throw new InvalidOperationException("IIS classic mode not supported");
            }

            var previewKey = Guid.NewGuid();

            PagePreviewContext.Save(previewKey, selectedPage, contents, renderingReason);

            // The header trick here is to work around (what seems to be) a bug in .net 4.5, where preserveForm=false is ignored
            // asp.net 4.5 request validation will see the 'page edit http post' data and start bitching. It really should not.
            var headers = new System.Collections.Specialized.NameValueCollection
            {
                { "Content-Length", "0" }
            };

            var    ctx          = HttpContext.Current;
            string cookieHeader = ctx.Request.Headers["Cookie"];

            if (!string.IsNullOrEmpty(cookieHeader))
            {
                headers.Add("Cookie", cookieHeader);
            }

            string previewPath = $"~/Renderers/PagePreview?{PagePreviewContext.PreviewKeyUrlParameter}={previewKey}";

            ctx.Server.TransferRequest(previewPath, false, "GET", headers);

            return(String.Empty);
        }
Esempio n. 7
0
 public C1RenderingReasonConstraint(RenderingReason reason)
 {
     _reason = reason;
 }
Esempio n. 8
0
        public static void Save(Guid previewKey, IPage selectedPage, IList <IPagePlaceholderContent> contents, RenderingReason renderingReason)
        {
            var cache = HttpRuntime.Cache;

            cache.Add(CacheKey_Page(previewKey), selectedPage, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
            cache.Add(CacheKey_Contents(previewKey), contents, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
            cache.Add(CacheKey_RenderingReason(previewKey), renderingReason, null, Cache.NoAbsoluteExpiration, PreviewExpirationTimeSpan, CacheItemPriority.NotRemovable, null);
        }