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
    1 week ago
    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 750 posts 2817 karma points c-trib
    1 week ago
    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
    1 week ago
    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

Please Sign in or register to post replies

Write your reply to:

Draft