Copied to clipboard

Flag this post as spam?

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


  • Marcel van der meulen 3 posts 73 karma points
    Jan 14, 2016 @ 16:01
    Marcel van der meulen
    0

    Request forwarding in Umbraco v6.2.4

    In a umbraco site (v6.2.4 webforms) we want to execute some logic before anything else kicks off. Basically we want to forward a request with a specific url to a web API service and send the response of that call back to the client. We already have some logic in place to call the webapi service, however we need something in umbraco to match a specific api call and execute that logic.

    In a ASP web API project you can create a routetemplate to match all requests starting with /test/api and have a DelegatingHandler execute the logic instead of webapi handling the request. We use the code below for that. We really like to know if Umbraco has something similar we can use. We really appreciate any help! If something is not clear feel free to ask.

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "Proxy",
                routeTemplate: "test/api/{*path}",
                handler: HttpClientFactory.CreatePipeline
                (
                    innerHandler: new HttpClientHandler(),
                    handlers: new DelegatingHandler[] { new ProxyHandler() }
                ),
                defaults: new { path = RouteParameter.Optional },
                constraints: null
            );
        }
    }
    
  • Marcel van der meulen 3 posts 73 karma points
    Jan 15, 2016 @ 11:37
    Marcel van der meulen
    0

    Solved it

    using System.Web.Routing;
    using Umbraco.Core;
    using MyApp;
    
    namespace MyProject.EventHandlers
    {
        public class RegisterEvents : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                RouteTable.Routes.Add(
                    "RouteName",
                    new Route("test/api/{*path}", new CustomRouteHandler("~/test.aspx"))
                );
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft