Copied to clipboard

Flag this post as spam?

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


  • Filur 20 posts 154 karma points
    May 23, 2017 @ 12:58
    Filur
    0

    Modify Umbraco's web api route?

    By default, Umbraco's web api controllers uses the following route: ~/Umbraco/Api/[YourControllerName].

    The documentation states: "Just like Surface Controllers in Umbraco, when you inherit from the base class Umbraco.Web.WebApi.UmbracoApiController we will auto-route this controller so you don't have to worry about routing at all."

    What if I want to use another route? In my case I would like to use ~/Api/v1/[ControllerName]. Is this possible?

  • Filur 20 posts 154 karma points
    May 23, 2017 @ 13:15
    Filur
    0

    I think that I figured it out:

    1. Create a new web api config class:

      public static class WebApiConfig
      {
          public static void Register(HttpConfiguration config)
          {
              config.Routes.MapHttpRoute(
                  name: "DefaultApi",
                  routeTemplate: "api/{controller}/{id}",
                  defaults: new { id = RouteParameter.Optional }
              );
          }
      }
      
    2. Register it in the Application_Started event: WebApiConfig.Register(GlobalConfiguration.Configuration);

    At a first glance it looks ok. Please let me know if I missed anything obvious

Please Sign in or register to post replies

Write your reply to:

Draft