Custom routes with virtual paths

Posted by Community Admin on 04-Aug-2018 13:15

Custom routes with virtual paths

All Replies

Posted by Community Admin on 27-Mar-2015 00:00

Hi

 Can someone please assist, I've been doing a lot of research on how to get this to work, but can't seem to get it to work. I have the same issue as David here : www.sitefinity.com/.../url-routing

 The problem is when adding custom routing that I get a 404 error, but I am sure its because the page does not exists, its a virtual page created via the backend of Sitefinity with a custom usercontrol on the page handling the logic.

 

How can I handle custom routes in Sitefinity 6?

 

I have this :

www.mysite.com/pagename

 When I search for "Shoes" on this page it needs to display as :

www.mysite.com/pagename/categories/shoes

So what I wanted to do was create custom routes for this, but I can't seem to get this to work.

I tried this :

Global.asax

protected void Application_Start(object sender, EventArgs e)
       
            Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);
       

 

Custom handler:
   public class CustomHttpHandler : IRouteHandler
   

        public CustomHttpHandler(string virtualPath)
       
            this.VirtualPath = virtualPath;
       

        public string VirtualPath get; private set;

        public IHttpHandler GetHttpHandler(RequestContext requestContext)
       
            var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page)) as IHttpHandler;
            return page;
       

        public bool IsReusable
       
            get return false;
       

   

 

Routes:

void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs args)
       
            if (args.CommandName == "RegisterRoutes")
           
                var routes = ((EnumerableQuery<RouteBase>)args.Data).ToList();
                routes.Insert(0, new System.Web.Routing.Route("blog/category/Category", new CustomHttpHandler("/blog")));
           
       

 

Kind Regards,

Gerrit

Posted by Community Admin on 01-Apr-2015 00:00

Hi Gerrit,

You can take a look on the similar issue discussed in that forum thread:
http://www.sitefinity.com/developer-network/forums/general-discussions-/url-routing-in-sitefinity-5-0

Regards,
Svetoslav Manchev
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
 

Posted by Community Admin on 01-Apr-2015 00:00

Thank you Svetoslav,

 We ended up to go a different route because of this issue. For those who have trouble with this, for us it work by adding additional URL's to the specific page, and then redirecting to the additional url.

 Kind Regards,

This thread is closed