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
);
}
}
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"))
);
}
}
}
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.
Solved it
is working on a reply...