Copied to clipboard

Flag this post as spam?

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


  • Sören Deger 726 posts 2833 karma points c-trib
    Nov 28, 2014 @ 16:21
    Sören Deger
    0

    Custom route for webApiController

    Hi all,

    I can call my webApiController with this url:

    http://localhost:52125/umbraco/api/myControllerName/getAll

    But the webApiController must be available at this url:

    http://localhost:52125/myApi/myControllerName/getAll

    How can I do this in umbraco 7.1.8?

     

    Cheers,

    Sören

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Dec 01, 2014 @ 08:47
    Sebastiaan Janssen
    100

    Try something like this:

    using System.Linq;
    using System.Web.Http;
    using System.Web.Mvc;
    using System.Web.Routing;
    using Umbraco.Core;
    
    namespace MyNamespace
    {
        public class MyApplicationEventHandler : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                RouteTable.Routes.MapHttpRoute(
                    "MyCustomApiRoute",
                    "MyApi/{controller}/{id}", new { id = UrlParameter.Optional });     
            }
        }
    }
    
  • Sören Deger 726 posts 2833 karma points c-trib
    Dec 01, 2014 @ 09:11
    Sören Deger
    0

    Great :) Thank you!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies