An alternative would be to use "Attribute routing". Then you could do something like this
public class AttributeRoutingComponent :IComponent
{
public void Initialize()
{
GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
}
public void Terminate()
{
}
}
public class AttributeRoutingComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<AttributeRoutingComponent>(); ;
}
}
public class ProductsController : UmbracoApiController
{
[Route("products/rates")]
public string Rates()
{
//Do stuff
}
}
Then you could access it via products/rates. You can read more about it here
How to remove /Umbraco/API/ from Url
Hi
I have a Umbraco API Controller "Products" and a API "Rates".
public class ProductsController : UmbracoApiController
public JObject Rates()
It gives me a Url "~/Umbraco/API/Products/Rates" how can I remove the "/Umbraco/API/" from the Url so it looks like "~/Products/Rates"??
How you can help :-)
Hi Lars,
You can Rewrite the urls by adding this to your web.config inside of system.webServer
It will rewrite the url from ~/Umbraco/API/Products/Rates to ~/API/Products/Rates
I would not recommend to remove the api completely, but you can by changing.
to
This code also rewrites it for the surface controllers.
Hi Lars!
An alternative would be to use "Attribute routing". Then you could do something like this
Then you could access it via
products/rates
. You can read more about it hereHope this helps you get on the right track!
//Johannes
I agree with Johannes, if you have a new set up then Attribute routing would be the way to go.
My recommendation only works for Version 8 and lower.
is working on a reply...