private string GetDetailsPageUrl(bool isForSale)
        {
            if (isForSale)
            {
                if (forSalePageUrl.IsNullOrEmpty() && !this.ForSalePageId.Equals(Guid.Empty))
                {
                    PageNode pageNode = App.WorkWith().Page(this.ForSalePageId).Get();

                    if (pageNode != null)
                    {
                        forSalePageUrl = pageNode.GetFullUrl();
                    }
                }

                return(forSalePageUrl);
            }
            else
            {
                if (forRentPageUrl.IsNullOrEmpty() && !this.ForRentPageId.Equals(Guid.Empty))
                {
                    PageNode pageNode = App.WorkWith().Page(this.ForRentPageId).Get();

                    if (pageNode != null)
                    {
                        forRentPageUrl = pageNode.GetFullUrl();
                    }
                }

                return(forRentPageUrl);
            }
        }
        public void CustomWidgetOnTemplate_RequestPage_ShouldLogOnlyWidgetExecution()
        {
            PageNode pageNode   = null;
            Guid     templateId = Guid.Empty;

            try
            {
                pageNode = this.CreatePageOnTemplateWithCustomWigdet(out templateId);
                var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetFullUrl());

                this.ClearData();
                this.ExecuteAuthenticatedRequest(fullPageUrl);
                this.FlushData();

                this.AssertWidgetExecutionCount(1);
                this.AssertViewCompilationCount(0);
            }
            finally
            {
                this.DeletePages(pageNode);
                if (templateId != Guid.Empty)
                {
                    ServerOperations.Templates().DeletePageTemplate(templateId);
                }
            }
        }
    protected void lvPages_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType != ListViewItemType.DataItem)
        {
            return;
        }

        PagesConfig pagesConfig = Config.Get <PagesConfig>();

        PageSiteNode node = (PageSiteNode)e.Item.DataItem;
        PageNode     page = pageManager.GetPageNode(node.Id);

        if (!node.ShowInNavigation || string.IsNullOrEmpty(node.Title))
        {
            e.Item.Visible = false;
            return;
        }

        HyperLink hlPage = (HyperLink)e.Item.FindControl("hlPage");

        hlPage.Text        = node.Title;
        hlPage.NavigateUrl = page.GetFullUrl(Thread.CurrentThread.CurrentCulture, false);

        if (node.HasChildNodes)
        {
            ListView lvPages = e.Item.FindControl("lvPages") as ListView;
            if (lvPages != null)
            {
                lvPages.DataSource = node.ChildNodes;
                lvPages.DataBind();
            }
        }
    }
Beispiel #4
0
        /// <summary>
        /// Gets the linked page URL.
        /// </summary>
        /// <returns></returns>
        protected virtual string GetLinkedUrl()
        {
            if (this.IsPageSelectMode)
            {
                if (this.LinkedPageId == Guid.Empty)
                {
                    if (!string.IsNullOrEmpty(this.LinkedUrl))
                    {
                        return(this.LinkedUrl);
                    }

                    return(null);
                }

                var pageManager = PageManager.GetManager();

                PageNode node = null;

                // The idea is to get the page and so that the URL can be generated on the frontend and when
                // a user that does not have permissions clicks it, they will be taken to the login screen
                using (new ElevatedModeRegion(pageManager))
                {
                    node = pageManager.GetPageNode(this.LinkedPageId);
                }

                if (node != null)
                {
                    string relativeUrl;
                    if (SystemManager.CurrentContext.CurrentSite.Cultures.Length > 1)
                    {
                        relativeUrl = node.GetFullUrl(Telerik.Sitefinity.Services.SystemManager.CurrentContext.Culture, false);
                    }
                    else
                    {
                        relativeUrl = node.GetFullUrl(null, false, true);
                    }

                    return(UrlPath.ResolveUrl(relativeUrl, Config.Get <SystemConfig>().SiteUrlSettings.GenerateAbsoluteUrls));
                }
            }
            else if (!string.IsNullOrEmpty(this.LinkedUrl))
            {
                return(this.LinkedUrl);
            }

            return(null);
        }
Beispiel #5
0
        protected virtual string ResolveDefaultSiteUrl(PageNode actualPageNode, CultureInfo cultureInfo)
        {
            var fullUrl = actualPageNode.GetFullUrl(cultureInfo, false, false);
            var siteUrl = this.UrlService.ResolveUrl(fullUrl, cultureInfo);

            siteUrl = RouteHelper.ResolveUrl(siteUrl, UrlResolveOptions.Absolute);
            return(siteUrl);
        }
        public void MixedWidgets_RequestPage_ShouldLogRazorViewCompilation()
        {
            var      viewRelativePath = "~/Mvc/Views/Test/Index.cshtml";
            PageNode pageNode         = null;

            try
            {
                var pageTitle = "TestPage1";
                ServerOperations.Pages().CreateTestPage(Guid.NewGuid(), pageTitle);

                var pageManager = PageManager.GetManager();
                pageNode = pageManager.GetPageNodes().SingleOrDefault(p => p.Title == pageTitle);

                var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetFullUrl());

                this.ClearData();
                this.ExecuteAuthenticatedRequest(fullPageUrl);
                this.FlushData();

                this.AssertWidgetExecutionCount(0);
                this.AssertViewCompilationCount(0);

                this.AddMixedWidgetsToPage(pageNode);
                this.ExecuteAuthenticatedRequest(fullPageUrl);

                this.ClearData();
                this.ExecuteAuthenticatedRequest(fullPageUrl);
                this.FlushData();

                var mvcWidgetCount = 1;
                this.AssertWidgetExecutionCount(mvcWidgetCount);
                this.AssertViewCompilationCount(0);

                var viewContent = string.Empty;
                this.CreateView(viewRelativePath, viewContent);

                var viewPath = "~/Frontend-Assembly/FeatherWidgets.TestIntegration/Mvc/Views/Test/Index.cshtml";
                this.WaitForAspNetCacheToBeInvalidated(viewPath);

                this.ClearData();
                this.ExecuteAuthenticatedRequest(fullPageUrl);
                this.FlushData();

                this.AssertWidgetExecutionCount(mvcWidgetCount);
                this.AssertViewCompilationCount(mvcWidgetCount);

                var rootOperationId       = this.GetRequestLogRootOperationId(fullPageUrl);
                var widgetCompilationText = "Compile view \"Index.cshtml\" of controller \"" + typeof(TestController).FullName + "\"";
                this.AssertViewCompilationParams(rootOperationId, viewPath, widgetCompilationText);
            }
            finally
            {
                this.DeletePages(pageNode);
                this.DeleteView(viewRelativePath);
            }
        }
Beispiel #7
0
        protected virtual string ResolveDefaultSiteUrl(PageNode actualPageNode, CultureInfo cultureInfo)
        {
            var  pageUrl            = actualPageNode.GetFullUrl(cultureInfo, false, false);
            var  pageUrlWithCulture = this.UrlService.ResolveUrl(pageUrl, cultureInfo);
            Guid rootNodeId         = actualPageNode.RootNodeId != Guid.Empty ? actualPageNode.RootNodeId : actualPageNode.Id;

            var site            = SystemManager.CurrentContext.MultisiteContext.GetSiteBySiteMapRoot(rootNodeId);
            var siteUrl         = this.GetSiteUrl(site);
            var relativeItemUrl = RouteHelper.ResolveUrl(pageUrlWithCulture, UrlResolveOptions.CurrentRequestRelative);
            var result          = string.Concat(VirtualPathUtility.RemoveTrailingSlash(siteUrl), relativeItemUrl);

            return(result);
        }
        public void CustomWidgetOnTemplate_EditView_ShouldLogCompilation()
        {
            var      viewRelativePath = "~/Mvc/Views/Test/Index.cshtml";
            PageNode pageNode         = null;
            Guid     templateId       = Guid.Empty;

            try
            {
                pageNode = this.CreatePageOnTemplateWithCustomWigdet(out templateId);
                var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetFullUrl());

                var viewContent = string.Empty;
                this.CreateView(viewRelativePath, viewContent);

                var viewPath = "~/Frontend-Assembly/FeatherWidgets.TestIntegration/Mvc/Views/Test/Index.cshtml";
                this.WaitForAspNetCacheToBeInvalidated(viewPath);

                this.ClearData();
                this.ExecuteAuthenticatedRequest(fullPageUrl);
                this.FlushData();

                this.AssertWidgetExecutionCount(1);
                this.AssertViewCompilationCount(1);

                var rootOperationId       = this.GetRequestLogRootOperationId(fullPageUrl);
                var widgetCompilationText = "Compile view \"Index.cshtml#Bootstrap.cshtml\" of controller \"" + typeof(TestController).FullName + "\"";
                this.AssertViewCompilationParams(rootOperationId, viewPath, widgetCompilationText);

                this.ClearData();
                this.ExecuteAuthenticatedRequest(fullPageUrl);
                this.FlushData();

                this.AssertWidgetExecutionCount(1);
                this.AssertViewCompilationCount(0);
            }
            finally
            {
                this.DeletePages(pageNode);
                this.DeleteView(viewRelativePath);
                if (templateId != Guid.Empty)
                {
                    ServerOperations.Templates().DeletePageTemplate(templateId);
                }
            }
        }
Beispiel #9
0
        public static string GetPageFullUrl(Guid pageId)
        {
            string pageFullUrl = String.Empty;

            PageManager pageManager = PageManager.GetManager();

            if (pageManager != null)
            {
                PageNode pageNode = pageManager.GetPageNodes().Where(n => n.Id == pageId).FirstOrDefault();
                // We will get the url as ~/homepage
                // So removing the first character
                if (pageNode != null)
                {
                    pageFullUrl = pageNode.GetFullUrl().Substring(1);
                }
            }

            return(pageFullUrl);
        }
        public void CustomWidget_RequestPage_ShouldLogOnlyWidgetExecution()
        {
            PageNode pageNode = null;

            try
            {
                pageNode = this.CreatePageWithCustomWidget();
                var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetFullUrl());

                this.ClearData();
                this.ExecuteAuthenticatedRequest(fullPageUrl);
                this.FlushData();

                this.AssertWidgetExecutionCount(1);
                this.AssertViewCompilationCount(0);
            }
            finally
            {
                this.DeletePages(pageNode);
            }
        }
Beispiel #11
0
        public void Application_Error(Object sender, EventArgs e)
        {
            // check to see if something horrible is going on...
            if (HttpContext.Current.Request.Headers["Custom-Error-Request"] != null)
            {
                // looks like a request to grab an error page ended up here. let's bail.
                return;
            }

            // get the last error
            HttpException err = HttpContext.Current.Server.GetLastError() as HttpException;

            HttpContext.Current.Server.ClearError();

            // try to skip using any other custom error settings
            HttpContext.Current.Response.TrySkipIisCustomErrors = true;

            // check to see if we need to send back something pretty
            var acceptsHtml = HttpContext.Current.Request.Headers["Accept"].Contains("text/html");

            // we're on!
            if (err != null && acceptsHtml)
            {
                // get the language from the visitor's browser settings
                string lang    = (HttpContext.Current.Request.UserLanguages ?? Enumerable.Empty <string>()).FirstOrDefault();
                var    culture = CultureInfo.GetCultureInfo(lang);

                // set the culture to match the browser language. (this makes it incredibly easy
                // to return the correct language version, if applicable.)
                Thread.CurrentThread.CurrentUICulture = culture;

                // get the page node associated with the current error
                PageNode pNode = GetPageAssociatedWithHttpCode(err.GetHttpCode());

                // set the worst case response to visitor
                string html = err.GetHttpCode().ToString();

                if (pNode != null)
                {
                    // grab the URL of the error page we're going to display to the visitor
                    string url = pNode.GetFullUrl(culture, true);
                    url = UrlPath.ResolveUrl(url, true, true);

                    // grab the entire HTML of the page
                    WebClient client = new WebClient {
                        Encoding = Encoding.UTF8
                    };
                    client.Headers.Add("Custom-Error-Request", "");

                    try
                    {
                        html = client.DownloadString(url);
                    }
                    catch (WebException ex)
                    {
                        // the error page is probably blowing up. maybe do some logging...or send an email? ¯\_(ツ)_/¯
                    }
                }

                // send back the the best response we got for the error and a status code
                HttpContext.Current.Response.Write(html);
                HttpContext.Current.Response.StatusCode = err.GetHttpCode();
                HttpContext.Current.Response.End();
            }
            else if (err != null)
            {
                // just fire back a basic message and the status
                HttpContext.Current.Response.Write(err.GetHttpCode().ToString());
                HttpContext.Current.Response.StatusCode = err.GetHttpCode();
            }
        }
 protected virtual string ResolveDefaultSiteUrl(PageNode actualPageNode, CultureInfo cultureInfo)
 {
     var fullUrl = actualPageNode.GetFullUrl(cultureInfo, false, false);
     var siteUrl = this.UrlService.ResolveUrl(fullUrl, cultureInfo);
     siteUrl = RouteHelper.ResolveUrl(siteUrl, UrlResolveOptions.Absolute);
     return siteUrl;
 }