Route hijacking problem mapping template to custom controller
I have a controller here called 'ReverseProxyController'
public class ReverseProxyController : Umbraco.Web.Mvc.RenderMvcController
{
public ActionResult ReverseProxy.....
I have also created a Document Type called 'Reverse Proxy'
But when I create a Template called 'Reverse Proxy' it maps straight to Views/ReverseProxy instead of getting hijacked and going to the ReverseProxyController
Eg do you have a content item created using the ReverseProxy Document Type?
If you can request the Url of that page, whilst debugging and setup an additional 'Index' route in your controller, you can set some breakpoints and see if it's hitting the controller first at all...
eg
public override ActionResult Index(RenderModel model)
{
//set a breakpoint here
return CurrentTemplate(model);
}
When a request comes into Umbraco it tries to find content matching that Url, looks up it's document type, uses the alias of the document type to see if a controller has been created in the format docTypeAliasController, then looks to see which template the page has been published with, looks for an action on the controller matching that alias, then fallback to use the Index action...
I'm assuming too that your ReverseProxy ActionResult accepts a 'RenderModel' object
public ActionResult ReverseProxy(RenderModel model)
{
??
Anyway be interesting to see how far you are getting in the process!
Good you got it working, yes, that's generally the convention to follow, you can add an alternative template to the doc type, and create an alternative action result matching the template name, but you also have to request the page 'WITH' that alt template - using ?altTemplate= to get the request routed to the alternative action, but usually you don't need to do this as you've found!
Route hijacking problem mapping template to custom controller
I have a controller here called 'ReverseProxyController'
I have also created a Document Type called 'Reverse Proxy'
But when I create a Template called 'Reverse Proxy' it maps straight to Views/ReverseProxy instead of getting hijacked and going to the ReverseProxyController
Not sure what I am missing, I went through the documentation and read the following forum post but I still can't get it to work. https://our.umbraco.com/documentation/reference/routing/custom-controllers
https://our.umbraco.com/forum/using-umbraco-and-getting-started/84844-route-hijacking-with-custom-controller
Hi Person2
What is the Url that you are requesting?
Eg do you have a content item created using the ReverseProxy Document Type?
If you can request the Url of that page, whilst debugging and setup an additional 'Index' route in your controller, you can set some breakpoints and see if it's hitting the controller first at all...
eg
When a request comes into Umbraco it tries to find content matching that Url, looks up it's document type, uses the alias of the document type to see if a controller has been created in the format docTypeAliasController, then looks to see which template the page has been published with, looks for an action on the controller matching that alias, then fallback to use the Index action...
I'm assuming too that your ReverseProxy ActionResult accepts a 'RenderModel' object
??
Anyway be interesting to see how far you are getting in the process!
regards
Marc
Maybe I misunderstood the documentation. But I have it working now.
If I create a Document Type with the controller name then it will automatically create a Template as well, which works how I want.
But I was trying to manually add a Template after the Document Type and I think that was overriding.
Hi person2
Good you got it working, yes, that's generally the convention to follow, you can add an alternative template to the doc type, and create an alternative action result matching the template name, but you also have to request the page 'WITH' that alt template - using ?altTemplate= to get the request routed to the alternative action, but usually you don't need to do this as you've found!
regards
marc
Thanks Marc
is working on a reply...