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

Forums / Bugs & Issues / Custom routes with virtual paths

Custom routes with virtual paths

3 posts, 0 answered
  1. Gerrit
    Gerrit avatar
    30 posts
    Registered:
    28 Jul 2010
    27 Mar 2015
    Link to this post

    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 : http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/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

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    01 Apr 2015
    Link to this post
    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
     
  3. Gerrit
    Gerrit avatar
    30 posts
    Registered:
    28 Jul 2010
    01 Apr 2015 in reply to Svetoslav Manchev
    Link to this post

    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,

3 posts, 0 answered