Cannot find the Umbraco route definition in the route values when using custom Routes
Hi Guys,
I have experiencing an error when using custom routes.
I have the below custom route:
public class CustomRoutesApplicationEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
RouteTable.Routes.MapUmbracoRoute(
ConstantValues.ProductsSearchCustomRouteName,
"search/{" + ConstantValues.ProductsCategoriesRouteParamName + "}/",
new
{
controller = "Products",
action = "Products"
},
new UmbracoVirtualNodeByIdRouteHandler(ConstantValues.ProductsPageId)
);
}
}
When I get the full url for the route url and acutally redirect to that url, I am getting the below error:
Cannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Cannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request
I essentially have the same problem as Simon, that when I use custom routes, the current page property throws an invalid operation exception. Is there a way to set the current page when routing to the custom page by using the code below.
We have a service routing for the methods we want available outside umbraco but for all other stuff we use route hijacking. Both ways work, but it looks like you want to combine these two?
Essentially what I am trying to do is access the current page property from a custom routed page. The reason I need access to it is because the master page has an action method which uses the current page property and when trying to access it, an invalid operation exception is thrown. This works for any umbraco page however, when used in the page that routed by a custom route the current page throws an exception. If current page is only set when using umbraco page (which I assume it is), then yes, I am essentially trying to partially combine the two together by setting the current page property during the routing method if there is a way. Because the current page property throws the exception even when mimicking an umbraco node during the routing method which is done here:
Thanks for your prompt reply. The end goal for this is essentially to load masterpage specific content using the current page property. The reason routing is used is because the listing for properties is loaded from a separate database and not from the umbraco db. Therefore, routing was necessary to load the controller and method which will load the custom page. A umbraco page was mimicked with the custom route only to have access to the document type alias and page id, these are necessary to load the masterpage specific content such as (JS scripts, menu items, etc...).
Why Don't you Hijack the route on the page by having a controller inheriting the RenderMvcController with the name of the document type and use that to get the content you need? This leaves the routing intact and you can append all the info you want to the model.
But if I understand the problem correctly, he wants to show extra information on a existing content page in Umbraco right?
In that cast the route hijacking way would be the way to go right? The extra content is coming from a different database so the virtual rout isn't the obvious choice right?
If I didn't understand the problem correctly than I'm out :P
That would work, if I was using the umbraco url. The problem is that I have a custom url which holds search parameters, therfore I cannot use the umbraco url. The url has to be custom build to store these search parameters. The items are then retrieved based on those parameters in the url.
Sorry, I did miss it. Currently my controller inherits from the surface controller. However, I did try it with render RenderMvcController and it still threw an invalid operation exception.
Cannot find the Umbraco route definition in the route values when using custom Routes
Hi Guys,
I have experiencing an error when using custom routes.
I have the below custom route:
When I get the full url for the route url and acutally redirect to that url, I am getting the below error:
Can anyone give me some insight about this?
Thank you in advance.
Kind Regards
Hi Guys,
My Problem is that when I am trying to use custom Routes, when trying to access the
CurrentPage
it is throwing the above error.For some reason, when using custom Routes, when goes back to the surface controller, the CurrentPage is not accessible.
Any help would be much appreciated.
Thank you
Kind Regards
Hi Guys,
I essentially have the same problem as Simon, that when I use custom routes, the current page property throws an invalid operation exception. Is there a way to set the current page when routing to the custom page by using the code below.
Here is my custom route:
Thanks for any help in advance.
Kind Regards
What are you trying to acomplish?
We have a service routing for the methods we want available outside umbraco but for all other stuff we use route hijacking. Both ways work, but it looks like you want to combine these two?
Frans
Hi Frans,
Essentially what I am trying to do is access the current page property from a custom routed page. The reason I need access to it is because the master page has an action method which uses the current page property and when trying to access it, an invalid operation exception is thrown. This works for any umbraco page however, when used in the page that routed by a custom route the current page throws an exception. If current page is only set when using umbraco page (which I assume it is), then yes, I am essentially trying to partially combine the two together by setting the current page property during the routing method if there is a way. Because the current page property throws the exception even when mimicking an umbraco node during the routing method which is done here:
UmbracoVirtualNodeByIdRouteHandler(ConstantValues.PropertiesPageId)
Thanks for your help
Alex
Hi Frans,
Sorry to be a bother. But do you know of a way this can be accomplished?
Thanks,
Alex
Sorry, didn't see your post.
I don't think you can access CurrentPage in a custom route because Umbraco doesn't know what you'r doing. (somebody correct me if I'm wrong)
But I still don't understand what your end goal is. Maybe there is another way without the routing?
Are you trying to access the properties on a propertiespage or something? I / We need to see where you want to go to help you find the way there.
Frans
Hi Frans,
Thanks for your prompt reply. The end goal for this is essentially to load masterpage specific content using the current page property. The reason routing is used is because the listing for properties is loaded from a separate database and not from the umbraco db. Therefore, routing was necessary to load the controller and method which will load the custom page. A umbraco page was mimicked with the custom route only to have access to the document type alias and page id, these are necessary to load the masterpage specific content such as (JS scripts, menu items, etc...).
Thanks,
Alex
You can check this out. If you want to create Custom Routes in Umbraco. Here is the link of article http://maffrigby.com/using-custom-routes-in-umbraco/. May be by this way you can short out your problem.
Hi Simon,
Is your controller inheriting from SurfaceController or RenderMvcController.
Virtual routes don't work for Surface controllers.
Maybe you paste the code of your controller as well ? We use virtual routes quite often and never have issues with it.
Dave
Why Don't you Hijack the route on the page by having a controller inheriting the RenderMvcController with the name of the document type and use that to get the content you need? This leaves the routing intact and you can append all the info you want to the model.
https://our.umbraco.org/documentation/reference/routing/custom-controllers
Hi Frans,
Route Hijacking is something different than virtual routes.
With route hijacking you built your own controller to handle the routing of a specific doctype so you can add additional logic.
Virtual routes let's you define your own urls that point to a content item in Umbraco.
You can combine that with route hijacking.
Dave
Okay, that's new for me. Will dive into that.
But if I understand the problem correctly, he wants to show extra information on a existing content page in Umbraco right?
In that cast the route hijacking way would be the way to go right? The extra content is coming from a different database so the virtual rout isn't the obvious choice right?
If I didn't understand the problem correctly than I'm out :P
Frans
That would work, if I was using the umbraco url. The problem is that I have a custom url which holds search parameters, therfore I cannot use the umbraco url. The url has to be custom build to store these search parameters. The items are then retrieved based on those parameters in the url.
Alex
I asked this before in this thread, but maybe you missed it ? Is your controller for the route inherting SurfaceController or RenderMvcController ?
Dave
Hi Dave,
Sorry, I did miss it. Currently my controller inherits from the surface controller. However, I did try it with render RenderMvcController and it still threw an invalid operation exception.
Alex
Hi Alex,
It needs to inherit RenderMvcController.
SurfaceControllers are autorouted so you can not give them a custom route. See docs : https://our.umbraco.org/documentation/Reference/Routing/surface-controllers
Maybe you can post some code on how you register the route and of your RenderMvcController to see if we can find the source of the issue.
Dave
Hi Dave,
Sorry for the long wait. Here is a detailed process of what I am trying to accomplish:
This code used to route to the properties page:
This is the controller which is used to handle the routed page, it is only creating a master page model and returning it to the view:
This is the view used. The problem occurs in the layout which makes use of a child action method that requires the current page:
I am using this action which is called in the layout umbPagesLayout.cshtml:
This is the method which is causing the invalid operation exception when referencing the current page:
Thanks for your help,
Alex
Hi Alex,
In the last code snippet I asume you are using a SurfaceController
Can you do this instead of CurrentPage
I also see you use this code to get the UmbracoHelper
In a controller you can do this : this.Umbraco to get access to the umbracohelper.
Dave
Hi Dave,
Your solution worked great. Thanks a lot for your help.
Alex
Dave -- you d'man.
Although the solution from Dave works, changing the code to use
AssignedContentItem
instead ofCurrentPage
might not always be possible...You can also just define the missing Umbraco route definition in the
UmbracoVirtualNodeRouteHandler
:is working on a reply...