What is the best practice way of calling MapMvcAttributeRoutes in an Umbraco 8 application? In umbraco 7 I called it from an ApplicationEventHandler method (ApplicationStarted) but that's replaced with Composers/Components in umb8 I believe. I created a component but now get an error about a missing service for my custom route?
Unable to resolve type: MyWebsite.WidgetsController, service name:
where the controller is
[RoutePrefix("widgets")]
public class WidgetsController : Controller
{
[ChildActionOnly]
[Route("show")]
public ActionResult Show()
{
return PartialView();
}
}
and the view has
@Html.Action("Show", "Widgets")
Yes using Owin could be one option. Essentially I just want to register (the non umbraco) mvc routes in my application, so figured i need to call MapMvcAttributeRoutes somehow?
The Umbraco component is:
public class RegisterCustomRouteComponent : IComponent
{
public void Initialize()
{
RouteTable.Routes.MapMvcAttributeRoutes();
}
public void Terminate()
{
throw new NotImplementedException();
}
}
update: following another thread i found, i made my controller inherit from RenderMvcController so that umbraco "knows" about the controller/"service".
Did this work?
Because RouteTable.Routes.MapMvcAttributeRoutes(); does not what you're describing here.
It does map the routes you're using in your controller though.
I am reading up on https://our.umbraco.com/documentation/reference/routing/custom-routes where it states you need to do some other stuff.
Did you read that? I am trying the same thing but with an API, but am also struggling.
Hi - yes it worked.
So at this point I have a Component that calls "RouteTable.Routes.MapMvcAttributeRoutes();" and also a custom controller that inherits from RenderMvcController.
This was the only way i could register the routes for my custom controller methods even though the methods aren't concerning umbraco content. I figure it makes sense that this is how an "UmbracoApplication" would know about all of the registered routes (umbraco or not). Ideally i wouldn't need to use RenderMvcController if there was some other/simpler way
basically, my original question was how do i get an UmbracoApplication to honour the stock standard mvc route attribute on my custom controller method:
[Route("/my/custom/method")]
public ActionResult MyMethod()
Umbraco 8 and calling MapMvcAttributeRoutes
hi
What is the best practice way of calling MapMvcAttributeRoutes in an Umbraco 8 application? In umbraco 7 I called it from an ApplicationEventHandler method (ApplicationStarted) but that's replaced with Composers/Components in umb8 I believe. I created a component but now get an error about a missing service for my custom route?
thanks for the help
Could you provide some code and what error you're getting?
Or you could create a starting class which inherits from UmbracoDefaultOwinStartup, if all else fails.
thanks Sibren. The exception is
where the controller is
and the view has
Yes using Owin could be one option. Essentially I just want to register (the non umbraco) mvc routes in my application, so figured i need to call MapMvcAttributeRoutes somehow?
The Umbraco component is:
update: following another thread i found, i made my controller inherit from RenderMvcController so that umbraco "knows" about the controller/"service".
Did this work? Because
RouteTable.Routes.MapMvcAttributeRoutes();
does not what you're describing here.It does map the routes you're using in your controller though. I am reading up on https://our.umbraco.com/documentation/reference/routing/custom-routes where it states you need to do some other stuff. Did you read that? I am trying the same thing but with an API, but am also struggling.
I'll keep you informed!
Hi - yes it worked. So at this point I have a Component that calls "RouteTable.Routes.MapMvcAttributeRoutes();" and also a custom controller that inherits from RenderMvcController.
This was the only way i could register the routes for my custom controller methods even though the methods aren't concerning umbraco content. I figure it makes sense that this is how an "UmbracoApplication" would know about all of the registered routes (umbraco or not). Ideally i wouldn't need to use RenderMvcController if there was some other/simpler way
basically, my original question was how do i get an UmbracoApplication to honour the stock standard mvc route attribute on my custom controller method:
is working on a reply...