URL routing

Posted by Community Admin on 04-Aug-2018 20:40

URL routing

All Replies

Posted by Community Admin on 25-Jul-2011 00:00

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. 


Posted by Community Admin on 27-Jul-2011 00:00

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

Posted by Community Admin on 27-Jul-2011 00:00

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


Posted by Community Admin on 08-Aug-2011 00:00

Is there any update on this?

Posted by Community Admin on 11-Aug-2011 00:00

I want to know this as well!

Posted by Community Admin on 15-Aug-2011 00:00

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

Posted by Community Admin on 16-Aug-2011 00:00

That worked for my purposes. Thanks for your help.

Posted by Community Admin on 16-Sep-2011 00:00

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. 

Posted by Community Admin on 16-Sep-2011 00:00

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

Posted by Community Admin on 28-Sep-2011 00:00

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

Posted by Community Admin on 23-Jan-2012 00:00
Posted by Community Admin on 15-Mar-2012 00:00

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?

Posted by Community Admin on 15-Mar-2012 00:00

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?

This thread is closed