Copied to clipboard

Flag this post as spam?

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


  • Niels Henriksen 73 posts 276 karma points
    Nov 16, 2018 @ 09:40
    Niels Henriksen
    0

    Urlrewrite API call

    I have this api call http://domain/umbraco/api/shopapi/GetByid/[ID] but I want to use urlrewriting to use http://domain/api/shopapi/GetByid/[ID] instead.

    I have been trying the rewriting in web.config and I have right now

    I have never been good at rewriting so I need some help here.

    I was thinking about using the IContentFinder instead but I need to map that to a url instead of outputting the string i get.

  • Niels Henriksen 73 posts 276 karma points
    Nov 16, 2018 @ 12:56
    Niels Henriksen
    0

    Ok I solved it using

    public class EventHandler : IApplicationEventHandler { public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { //throw new NotImplementedException(); }

        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            WebApiConfig.Register(GlobalConfiguration.Configuration);
        }
    
        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //throw new NotImplementedException();
        }
    }
    
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "CustomApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft