+1-888-365-2779
Try Now
More in this section

URL routing

13 posts, 1 answered
  1. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    25 Jul 2011
    Link to this post
    On the SiteFinity 4 technology overpage (http://www.sitefinity.com/asp-net-cms-features/technology.aspx), it states:

    Sitefinity’s URL handling capabilities are built on the ASP.NET Routing Engine (formerly known as the ASP.NET MVC Routing Engine). This enables Sitefinity URLs to be extensionless, by default. It also enables Sitefinity to handle legacy URLs, or apply URL transformations. Developers are free to extend Sitefinity’s default URL handling behavior using their own customer routing rules.

    I highlighted this last sentence, as it's exactly what I'm trying to do. How does one "extend Sitefinity's default URL handling"? 

    I did see another recent forum post here: http://www.sitefinity.com/devnet/forums/sitefinity-4-x/developing-with-sitefinity/sitefinity-4-1-asp-net-url-routing.aspx. However, that seems to a.) workaround SiteFinity's URL routing and b.) require a physical ASPX file to exist in the project. 


  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    27 Jul 2011
    Link to this post
    Hello David,

    Can you give us more details about the specific scenario you have? It is hard discussing implementation details without knowing what you want to achieve in the first place.

    Regards,
    Slavo
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    27 Jul 2011
    Link to this post
    I was hoping there was something on URL routing in the documentation, but I couldn't find anything.

    As an example implementation, let's say I want to use a site for cars with a parameter of {model}, so the URLs would look like this:

    1.) Url: /cars/{model}/features
      Resolve to: /cars/features?m={model}

    2.) Url: /cars/{model}/prices
      Resolve to: /cars/prices?m={model}

    So, the URL http://hostname/cars/corolla/features would lead to http://hostname/cars/features?m=corolla where /cars/features is a page I created within SiteFinity. 

    I was hoping I could add to the RouteTable as in Scott Guthrie's blog article (http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx) with a rule like:

    RouteTable.Routes.MapPageRoute("car-features",
     "cars/{model}/features",
     "~/cars/features");

    However, it appears that last parameter needs to be a physical file. SiteFinity's pages aren't actual ASPX files, so the built-in routing won't work. It looks like SiteFinity adding routes to the RouteTable collection, so I'm guessing there's a workaround.

    Thanks again,
    David


  4. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    08 Aug 2011
    Link to this post
    Is there any update on this?
  5. Rick de Vries
    Rick de Vries avatar
    7 posts
    Registered:
    22 Feb 2010
    11 Aug 2011
    Link to this post
    I want to know this as well!
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Aug 2011
    Link to this post
    Hello,

    Sitefinity uses its own route handlers to serve the non physical pages. The best option here would be to create a custom Route which inherits from SitefinityRoute and parse the URL data there:
    using System;
    using System.Globalization;
    using System.Web;
    using Telerik.Microsoft.Practices.Unity;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Localization.UrlLocalizationStrategies;
    using Telerik.Sitefinity.Modules.Pages.Configuration;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Web;
      
    namespace SitefinityWebApp
    {
        public class CustomSitefinityRoute: SitefinityRoute
        {
            public override System.Web.Routing.RouteData GetRouteData(HttpContextBase httpContext)
            {
                //get the path from the httpContext variable and parse it
                var virtuallPath = this.GetVirtualPathInternal(httpContext);
                if(virtuallPath.Contains("features"))
                {
                    //parse the acutal path to find the PageSiteNode from the sitemap provider
                    var sitemapProvider = this.GetSiteMapProvider();
                    if (sitemapProvider == null)
                        return null;
                    bool isAdditional;
                    string[] pars;
                    var node = sitemapProvider.FindSiteMapNode("path", false, out isAdditional, out pars);
                    if(node!=null)
                        return this.GetRouteDataInternal(pars, httpContext.Request.QueryString, node);
                }
               
                    return base.GetRouteData(httpContext);
            }
      
            public static void RegisterType()
            {
                ObjectFactory.Container.RegisterType<SitefinityRoute, CustomSitefinityRoute>();
            }
        }
    }

    Then substitute the default SitefinityRoute with the custom one (done in Global.asax):
    protected void Application_Start(object sender, EventArgs e)
    {
        Telerik.Sitefinity.Services.SystemManager.ApplicationStart += new EventHandler<EventArgs>(SystemManager_ApplicationStart);
    }
     
    void SystemManager_ApplicationStart(object sender, EventArgs e)
    {
       CustomSitefinityRoute.RegisterType();
    }


    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  7. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    16 Aug 2011
    Link to this post
    That worked for my purposes. Thanks for your help.
  8. Ray
    Ray avatar
    15 posts
    Registered:
    09 Jul 2008
    16 Sep 2011
    Link to this post
    Does this work in Sitefinity 4.2. I have copied everything exactly and in the Global.asax everything seems to regester but the CustomSitefinityRoute is never called. When any page request is called. 
  9. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    16 Sep 2011
    Link to this post
    One thing missing from their sample is actually registering CustomSitefinityRoute with ASP.Net routing rules. 

    I had to add the following to Global.asax:

    RouteTable.Routes.Insert(1, new CustomSitefinityRoute());

    I inserted the routing (rather than adding it to the end) because I wanted to my routes to go before SiteFinity's. 

    Hope that helps,
    David
  10. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Sep 2011
    Link to this post
    Hello,

    The sample provided substitutes the built in route in order to use its extended functionality. If you have a route handler which does not extend the Sitefinity route you have to register it as David does.

    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Doug Lubey
    Doug Lubey avatar
    31 posts
    Registered:
    17 Apr 2010
  12. Kunal Johar
    Kunal Johar avatar
    8 posts
    Registered:
    22 Jan 2010
    15 Mar 2012
    Link to this post
    I got all of this working, however when sitefinity loads the requested page, if it has generic content with images / links, it does not seem to pre-process them.  

    Any suggestions?
  13. Kunal Johar
    Kunal Johar avatar
    8 posts
    Registered:
    22 Jan 2010
    15 Mar 2012
    Link to this post
    I got all of this working, however when sitefinity loads the requested page, if it has generic content with images / links, it does not seem to pre-process them.  

    Any suggestions?
13 posts, 1 answered