Sitefinity url routing question

Posted by Community Admin on 03-Aug-2018 09:26

Sitefinity url routing question

All Replies

Posted by Community Admin on 21-Jul-2014 00:00

Hi  everybody, 

I'm using Sitefinity 6.3 .  I created  a "Test" page in Sitefinity. 

 I want to use a site for Test with a parameter .so the URL would look like this:

1.) Url: /Test /model
  Resolve to: /Test ?m=model

I have referred to the web site (http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/url-routing) ,  If I input "http://localhost:60876/test"  ,it's OK.  

But I input "localhost:60876/.../minco"  , it will show empty.

This my sample code .

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();
       

CustomSitefinityRoute.cs :

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("test"))
            
                //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("test", 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>();
        
    


Anybody can help me  ? 

 

Regards 

Minco

Posted by Community Admin on 24-Jul-2014 00:00

Hello,

Sitefinity support parameters in the URL, so you can use it for this issue. Sitefinity will load the last valid page in the path of the requested URL and the rest of the URL will be treated as URL parameters. In your example, if you start with ~/test, no matter what you place after it, the test page will be loaded and you can access the rest in the URL as parameters.

If you have a custom control/widget that relies on this parameters in the URL, you have to add this line of code to indicate that you have processed a specific parameters:

Telerik.Sitefinity.Web.RouteHelper.SetUrlParametersResolved();

Moreover, you can get all parameters with this code:

var params this.Request.RequestContext.RouteData.Values["Params"as string[];
if (params != null)
    ...

In addition you can take a look at this blog post: 404 and custom Parameters

Regards,
Pavel Uzunov
Telerik
 
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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

 

This thread is closed