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 733 posts 2844 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 5060 posts 15522 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 733 posts 2844 karma points c-trib
    Dec 01, 2014 @ 09:11
    Sören Deger
    0

    Great :) Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft