I have a problem with Umbraco routing all requests through the wrong controller.
Setup:
MVC, C#
Umbraco 7.2.8
2 Document types (school and forums) each having a template that matches the name of the document type.
The forums document type falls under the school document type in the content tree.
2 RenderMvcControllers named schoolcontroller and forumscontroller
The problem:
Whenever i type http://schoolproject:81/forums I expect Umbraco to route the request through the ForumsController. Instead, Umbraco routes the request through the schoolcontroller but still gives me the Forums view. This happens for any controller i make, all requests are routed through the schoolcontroller but still show the right view.
Tried solutions:
Created a new project with a clean Umbraco installation and still running into the same problem.
Am I missing something fundamental about Umbraco here? Is this the intended behaviour or am I doing something wrong?
Any insight is appreciated, Thank you.
What doctype is the content node /forums - is it a School? I'm confused by what you mean in point 4.?
My understanding is that Custom Controllers are hit based on the document type of the page requested - are you expecting it to hit "Forums" due to the URL - if this is of type "School" then it will hit the schools custom controller regardless of URL.
I'm not sure i understand, but Forums is the document type, School is also a document type. On the structure tab of the School document type i checked Forums as allowed child.
The montessori node is of the document type School and
the SchoolForums node is of the document type Forums.
public class ForumsController : RenderMvcController
{
public override ActionResult Index (RenderModel model)
{
return base.Index(model);
}
}
When i type http://schoolproject:81/forums I want the forums controller to be activated, but instead Umbraco keeps routing every request through the Schoolcontroller:
public class SchoolController : RenderMvcController
{
// GET: School
public override ActionResult Index (RenderModel model)
{
return base.Index(model);
}
}
But if you hit http://schoolproject:81/SchoolForums you will hit the ForumsController - right? Umbraco will match the URL based on the content tree - not on a custom controller / doctype mapping. So it will see SchoolForum - look at the doc type and the route this to the ForumController.
I've just tested your set up and hitting /forum routes to the school controller - guessing it's working up the content tree as it will fail to match to a content node (I'm sure someone here can explain why - I'm not sure, I'd have expected a 404).
What is it you're trying to do - can you just not rename the SchoolForums content node to "forum" if that's what you want?!?
My understanding is it's usually best to leave Umbraco to do the routing via the content and override only where necessary (which I guess it would be for a custom forum). Why have you even got a schools controller - can you not just let Umbraco deal with this bit?
This is very helpful, thank you for your reply. This is just me being new to Umbraco and umbraco behaving differently from what i expected i suppose :) I will mark your reply as answering my question.
Glad to help - would still like to know why it hits that School controller and not a 404 though if anyone can explain!
I think we could do with someone writing a "Moving from thinking MVC to Umbraco-MVC" tutorial / video.. but that someone would not be me :) . Seems to be a lot of .NET MVC folk new to Umbraco who get confused with this.
request routed through the wrong controller
I have a problem with Umbraco routing all requests through the wrong controller.
Setup:
The problem:
Whenever i type http://schoolproject:81/forums I expect Umbraco to route the request through the ForumsController. Instead, Umbraco routes the request through the schoolcontroller but still gives me the Forums view. This happens for any controller i make, all requests are routed through the schoolcontroller but still show the right view.
Tried solutions:
Created a new project with a clean Umbraco installation and still running into the same problem.
Am I missing something fundamental about Umbraco here? Is this the intended behaviour or am I doing something wrong? Any insight is appreciated, Thank you.
What doctype is the content node /forums - is it a School? I'm confused by what you mean in point 4.?
My understanding is that Custom Controllers are hit based on the document type of the page requested - are you expecting it to hit "Forums" due to the URL - if this is of type "School" then it will hit the schools custom controller regardless of URL.
See the paragraph under Creating a custom controller https://our.umbraco.org/documentation/reference/routing/custom-controllers
I hope I've got that right...
I hope this helps.
Under content you have something like:
I'm not sure i understand, but Forums is the document type, School is also a document type. On the structure tab of the School document type i checked Forums as allowed child.
The montessori node is of the document type School and the SchoolForums node is of the document type Forums.
When i type http://schoolproject:81/forums I want the forums controller to be activated, but instead Umbraco keeps routing every request through the Schoolcontroller:
But if you hit http://schoolproject:81/SchoolForums you will hit the ForumsController - right? Umbraco will match the URL based on the content tree - not on a custom controller / doctype mapping. So it will see SchoolForum - look at the doc type and the route this to the ForumController.
I've just tested your set up and hitting /forum routes to the school controller - guessing it's working up the content tree as it will fail to match to a content node (I'm sure someone here can explain why - I'm not sure, I'd have expected a 404).
What is it you're trying to do - can you just not rename the SchoolForums content node to "forum" if that's what you want?!?
My understanding is it's usually best to leave Umbraco to do the routing via the content and override only where necessary (which I guess it would be for a custom forum). Why have you even got a schools controller - can you not just let Umbraco deal with this bit?
I think you can probably do what you want but you need to look at this - and decide if you're going to totally overrule Umbraco's routing: http://shazwazza.com/post/Custom-MVC-routes-within-the-Umbraco-pipeline
This is very helpful, thank you for your reply. This is just me being new to Umbraco and umbraco behaving differently from what i expected i suppose :) I will mark your reply as answering my question.
Glad to help - would still like to know why it hits that School controller and not a 404 though if anyone can explain!
I think we could do with someone writing a "Moving from thinking MVC to Umbraco-MVC" tutorial / video.. but that someone would not be me :) . Seems to be a lot of .NET MVC folk new to Umbraco who get confused with this.
is working on a reply...