Copied to clipboard

Flag this post as spam?

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

  • David McDonnell 53 posts 250 karma points
    Jan 14, 2021 @ 15:12
    David McDonnell

    Invalid Url matches Controller and View name and returns 500 instead of 404

    Hi all, this sounds like a routing issue with Umbraco / MVC.

    I have a multi-lingual site, and on one of the sites we are not permitted to have some types of content.

    e.g. (this is permitted and page exists)

    and (this is not permitted and page does not exist)

    The permitted dashboard url renders to a controlller named "dashboardController" and a view named "dashboard"

    when I request which does not exist i do not get a 404 error instead I get a 500 server error that the model being passed to the dashboard view is incorrect.

    I am presuming that this is because of the naming convention of the controller and view matching "dashboard"

    is there anyway i can have Umbraco step in before MVC looks for a view and controller matching the url. At some level Umbraco is obvioulsy using this technique to match document types to the controllers and views

  • Marc Goodson 1415 posts 9546 karma points MVP 5x c-trib
    Jan 15, 2021 @ 15:07
    Marc Goodson

    Hi David

    There is a bit of history to this

    'Back in the day'

    There was a function to force an Umbraco Content Page to load with a different template to the one it was published with - eg to provide an XML feed, or mobile view of the page (it was a long time ago).

    To trigger this you added ?altTemplate=aliasOfTemplate to the Url to make this happen.

    A convention was established that if, at the end of url you called a 'file' with the name of alias that would do the same job, eg /aliasOfTemplate.aspx

    and then when 'everything went extensionless' the convention became just /aliasofTemplate

    which is why you can get issues if the last portion of a url matches a valid template in Umbraco, it tries to load the page beneath with the template, (and in some versions of V7 even when that page doesn't exist).

    If you don't rely on the altTemplate functionality in your site then you can turn it off!

    in /config/umbracosettings.config

    scrolll down right to the bottom to find the routing configuration:

        internalRedirectPreservesTemplate="false" disableAlternativeTemplates="true" validateAlternativeTemplates="false" disableFindContentByIdPath="false" disableRedirectUrlTracking="true"

    and set disableAlternativeTemplates to be 'true'

    (if you need the AltTemplate functionality in some circumstances, then you can leave it enabled and set validateAlternativeTemplates to be true, this will mean the template will only be loaded IF it's allowed to be displayed for the underlying node).



Please Sign in or register to post replies

Write your reply to: