URL routing - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

URL routing

  • URL routing
  • 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. 


  • 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
  • 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 hostname/.../featurescorolla 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


  • Is there any update on this?
  • I want to know this as well!
  • 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
  • That worked for my purposes. Thanks for your help.
  • 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. 
  • 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
  • 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
  • I did a full round trip example on this;  It is not great; but it works for now. 
    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/bugs-issues/question-how-to-integrate-url-rerouting-with-sitefinity-virtual-folder-structure-version-4-3-1885-0.aspx

    -doug lubey of louisiana
  • 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?
  • 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?