Exemple #1
0
        public static string[] GetPathInfoParts()
        {
            // Expecting '/yyyy/mm/dd/title' OR /tag
            string pathInfo = C1PageRoute.GetPathInfo();

            return(pathInfo != null && pathInfo.Contains("/") ? pathInfo.Split('/') : null);
        }
        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            if (!SystemSetupFacade.IsSystemFirstTimeInitialized)
            {
                return;
            }

            // Left for backward compatibility with Contrib master pages support, to be removed
            // when support for master pages is implemented in C1
            // RenderingContext.PreRenderRedirectCheck() does the same logic
            var httpContext = (sender as HttpApplication).Context;

            var page = httpContext.Handler as System.Web.UI.Page;

            if (page == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(C1PageRoute.GetPathInfo()))
            {
                page.PreRender += (a, b) => CheckThatPathInfoHasBeenUsed(httpContext, page);
            }

            // Setting 404 response code if it is a request to a custom "Page not found" page
            if (HostnameBindingsFacade.IsPageNotFoundRequest())
            {
                page.PreRender += (a, b) =>
                {
                    httpContext.Response.TrySkipIisCustomErrors = true;
                    httpContext.Response.StatusCode             = 404;
                };
            }
        }
Exemple #3
0
        /// <summary>
        /// Redirects to 404 page if PathInfo wasn't used. Adds 404 status code if the current page is specified as 404 page in hostname binding.
        /// Note that all C1 functions on page have to be executed before calling this method.
        /// </summary>
        /// <returns><c>True</c> if the request was transferred to a 404 page and rendering should be stopped.</returns>
        public bool PreRenderRedirectCheck()
        {
            var httpContext = HttpContext.Current;

            if (!C1PageRoute.GetPathInfo().IsNullOrEmpty() &&
                !C1PageRoute.PathInfoUsed)
            {
                // Redirecting to PageNotFoundUrl or setting 404 response code if PathInfo url part hasn't been used
                if (HostnameBindingsFacade.ServeCustomPageNotFoundPage(httpContext))
                {
                    return(true);
                }

                httpContext.Response.StatusCode = 404;
                httpContext.Response.End();
            }

            // Setting 404 response code if it is a request to a custom "Page not found" page
            if (HostnameBindingsFacade.IsPageNotFoundRequest())
            {
                httpContext.Response.StatusCode = 404;
            }

            return(false);
        }
Exemple #4
0
        protected override string GetMvcRoute(ParameterList parameters)
        {
            string route = _routeToRender;

            if (_handlePathInfo)
            {
                route += C1PageRoute.GetPathInfo() ?? string.Empty;
            }
            return(route);
        }
Exemple #5
0
        private static string GetPathInfo()
        {
            string result = C1PageRoute.GetPathInfo() ?? string.Empty;

            if (result != string.Empty)
            {
                C1PageRoute.RegisterPathInfoUsage();
            }

            return(result);
        }
        private void context_AcquireRequestState(object sender, EventArgs e)
        {
            if (!SystemSetupFacade.IsSystemFirstTimeInitialized)
            {
                return;
            }

            HttpContext httpContext = (sender as HttpApplication).Context;

            if (httpContext.Handler is Page page && !string.IsNullOrWhiteSpace(C1PageRoute.GetPathInfo()))
            {
                page.PreRender += (a, b) => CheckThatPathInfoHasBeenUsed(httpContext, page);
            }
        }
Exemple #7
0
        public object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            var httpContext = new HttpContextWrapper(HttpContext.Current);
            var pathInfo    = C1PageRoute.GetPathInfo();
            var path        = "/" + Namespace + "." + Name + pathInfo;

            var response = new NancyC1FunctionHost().ProcessRequest(httpContext, path, parameters);

            try
            {
                var document = ParseContent(response.Content);

                if (response.StatusCode != HttpStatusCode.NotFound)
                {
                    C1PageRoute.RegisterPathInfoUsage();
                }

                return(document);
            }
            catch (Exception)
            {
                if (response.Content.Contains("<title>404</title>"))
                {
                    return(null);
                }

                if (response.StatusCode == HttpStatusCode.InternalServerError)
                {
                    const string startTag = "<pre id=\"errorContents\">";
                    const string endTag   = "</pre>";

                    var start = response.Content.IndexOf(startTag, StringComparison.OrdinalIgnoreCase) + startTag.Length;
                    var end   = response.Content.IndexOf(endTag, start, StringComparison.OrdinalIgnoreCase);

                    var error = response.Content.Substring(start, end - start);

                    C1PageRoute.RegisterPathInfoUsage();

                    throw new HttpException(error);
                }

                httpContext.Response.Clear();
                httpContext.Response.Write(response.Content);
                httpContext.Response.End();

                return(null);
            }
        }
Exemple #8
0
        public object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            var route = GetMvcRoute(parameters);

            var routeData = GetRouteData(route, parameters);

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

            bool routeResolved = false;

            XhtmlDocument result;

            try
            {
                result = ExecuteRoute(routeData, parameters, out routeResolved);
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException ||
                    ex is HttpException ||
                    ex is ThreadInterruptedException ||
                    ex is StackOverflowException ||
                    ex is OutOfMemoryException)
                {
                    throw;
                }

                throw new InvalidOperationException($"Error executing route '{route}'", ex);
            }
            finally
            {
                if (routeResolved && HandlesPathInfo && C1PageRoute.GetPathInfo() != null)
                {
                    C1PageRoute.RegisterPathInfoUsage();
                }
            }

            if (result != null)
            {
                ProcessDocument(result, parameters);
            }

            return(result);
        }
        internal static string GetPathInfoSegment(int segment)
        {
            string pathInfo = C1PageRoute.GetPathInfo();

            if (segment == -1)
            {
                return(pathInfo);
            }

            string[] segments = (pathInfo ?? string.Empty).Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            if (segments.Length > segment)
            {
                return(segments[segment]);
            }

            return(null);
        }
Exemple #10
0
        public async Task <object> ExecuteAsync(ParameterList parameters, FunctionContextContainer context)
        {
            string virtualRoute = GetMvcRoute(parameters);
            var    routeData    = GetRouteData(virtualRoute, parameters);

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

            CultureInfo culture          = C1PageRoute.PageUrlData.LocalizationScope;
            var         publicationScope = C1PageRoute.PageUrlData.PublicationScope;

            var httpContext = HttpContext.Current;
            var result      = await ExecuteRouteAsync(routeData, httpContext, culture, publicationScope);

            if (result != null && C1PageRoute.GetPathInfo() != null)
            {
                C1PageRoute.RegisterPathInfoUsage();
            }

            return(result);
        }
        /// <summary>
        /// Appends the c1 meta tags to the head section. Those tag are used later on by SEO assistant.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="xhtmlDocument">The XHTML document.</param>
        public static void AppendC1MetaTags(IPage page, XhtmlDocument xhtmlDocument)
        {
            if (UserValidationFacade.IsLoggedIn())
            {
                bool emitMenuTitleMetaTag = string.IsNullOrEmpty(page.MenuTitle) == false;
                bool emitUrlMetaTag       = string.IsNullOrEmpty(page.UrlTitle) == false;

                if (emitMenuTitleMetaTag || emitUrlMetaTag)
                {
                    xhtmlDocument.Head.Add(
                        new XComment("The C1.* meta tags are only emitted when you are logged in"),
                        new XElement(Namespaces.Xhtml + "link",
                                     new XAttribute("rel", "schema.C1"),
                                     new XAttribute("href", "http://www.composite.net/ns/c1/seoassistant")));

                    if (emitMenuTitleMetaTag)
                    {
                        xhtmlDocument.Head.Add(
                            new XElement(Namespaces.Xhtml + "meta",
                                         new XAttribute("name", "C1.menutitle"),
                                         new XAttribute("content", page.MenuTitle)));
                    }

                    if (emitUrlMetaTag)
                    {
                        var editPreview = PageRenderer.RenderingReason == RenderingReason.PreviewUnsavedChanges;

                        string url = PageUrls.BuildUrl(page) ?? PageUrls.BuildUrl(page, UrlKind.Internal);

                        var pageUrl = string.Format("{0}{1}{2}",
                                                    url.Replace("/c1mode(unpublished)", "").Replace("/c1mode(relative)", ""),
                                                    editPreview ? "/" + page.UrlTitle : C1PageRoute.GetPathInfo(),
                                                    editPreview ? "" : HttpContext.Current.Request.Url.Query);

                        xhtmlDocument.Head.Add(
                            new XElement(Namespaces.Xhtml + "meta",
                                         new XAttribute("name", "C1.urlseowords"),
                                         new XAttribute("content", pageUrl)));
                    }
                }
            }
        }
        protected override string GetMvcRoute(ParameterList parameterList)
        {
            string pathInfo = C1PageRoute.GetPathInfo();

            return(GetBaseMvcRoute(parameterList) + pathInfo);
        }
Exemple #13
0
        private static string[] GetPathInfoParts()
        {
            var pathInfo = C1PageRoute.GetPathInfo() ?? string.Empty;

            return(pathInfo.Contains("/") ? pathInfo.Split('/') : null);
        }