Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sandra26 15 posts 115 karma points
    Oct 08, 2019 @ 13:35
    Sandra26
    0

    How to remove umbraco from url , creating custom routes

    Hi,

    I'm creating web api, using UmbracoApiController .

    I read https://our.umbraco.com/documentation/Reference/Routing/custom-routes and as a beginner I must admit I didn't find it very helpful.

    I'll really appreciate step by step instructions how to change the routes from /umbraco/api/controllerName/get?contentN=contentName to /api/v1/controllerName/contentName.

    Best , Sandra26

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Oct 08, 2019 @ 15:02
    David Brendel
    0

    Hi Sandra,

    you can't change the routes from the default wired routes to use your custom ones.

    What you can do is adding redirect in IIS from your custom url to the default umbraco ones. Via web.config or directly in IIS if you have access.

    Or what you can try is to register your custom urls in the RouteTable like it is stated in the docs. For example like this:

    RouteTable.Routes.MapHttpRoute(
                $"distinct route name",
                url, // url to match
                new { controller = controllerName, id = UrlParameter.Optional },
                new[] {controllerNamespace });
    

    Regards David

  • Sandra26 15 posts 115 karma points
    Oct 08, 2019 @ 15:12
    Sandra26
    0

    Hi David,

    I did that. I have problem how to implement FindContent(RequestContext requestContext, UmbracoContext umbracoContext)

     public class UmbracoVirtualNodeByNameRouteHandler : UmbracoVirtualNodeRouteHandler
        {
            public UmbracoVirtualNodeByNameRouteHandler(string contentName) { }
            protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
            {
    
            }
    
        }
    

    }

    Because I want go work with content name not with id like in the documentation. Best, Sandra26

  • Alberto Leon 2 posts 23 karma points
    Feb 18, 2021 @ 06:41
    Alberto Leon
    0

    Hi Sandra, Did you got it? I'm interested about how you did it!

  • Mehmet Avcı 55 posts 240 karma points
    Feb 18, 2021 @ 19:55
    Mehmet Avcı
    0

    Hi,

    Quite an old post. But since asked,

    In the VirtualNodeRouteHandler, FindContent method is overridden. Name is self explanatory but you need to find your umbraco node here.

    I myself use this to grab a dynamic page and place my content in it. So, what I need to do is to find this dynamic page's node.

    protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
        {
            return umbracoContext.ContentCache.GetByXPath($"//{PageNodeAlias}").First();
        }
    

    Depending on what you need, you can try to use a similar query to find your content.

Please Sign in or register to post replies

Write your reply to:

Draft