Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Martin 5 posts 85 karma points
    Sep 16, 2015 @ 07:50
    Martin
    0

    request routed through the wrong controller

    I have a problem with Umbraco routing all requests through the wrong controller.

    Setup:

    1. MVC, C#
    2. Umbraco 7.2.8
    3. 2 Document types (school and forums) each having a template that matches the name of the document type.
    4. The forums document type falls under the school document type in the content tree.
    5. 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.

  • Steve Morgan 1346 posts 4454 karma points c-trib
    Sep 16, 2015 @ 08:44
    Steve Morgan
    0

    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...

  • Martin 5 posts 85 karma points
    Sep 16, 2015 @ 09:04
    Martin
    0

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    I hope this helps.

  • Steve Morgan 1346 posts 4454 karma points c-trib
    Sep 16, 2015 @ 09:11
    Steve Morgan
    0

    Under content you have something like:

    • home
      • forums <- what is the doc type?
  • Martin 5 posts 85 karma points
    Sep 16, 2015 @ 09:37
    Martin
    0

    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.

    enter image description here

    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);
        }
    
    }
    
  • Steve Morgan 1346 posts 4454 karma points c-trib
    Sep 16, 2015 @ 10:10
    Steve Morgan
    100

    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

  • Martin 5 posts 85 karma points
    Sep 16, 2015 @ 11:04
    Martin
    0

    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.

  • Steve Morgan 1346 posts 4454 karma points c-trib
    Sep 16, 2015 @ 11:28
    Steve Morgan
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft