I am currently working on the 404 page not found and I noticed that if i have a Template name in the URL, it shows 500 Server error, instead of page not found.
I was expecting this will throw an 404 but it didn't, instead i got this error message
"The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'projectNamceSpace.Template1ViewModel'."
Since this is .net MVC, i thought it will goes through HomeController, as defined in the RouteConfig.cs. But it seems to bypass this configuration.
Does anyone have any idea how to show 404? instead of error message?
It will go to the HomeController, but when you're using an alt template it will go to a different ActionResult. For example if this is your HomeController:
public class HomeController : SurfaceRenderMvcController
{
public ActionResult Home(RenderModel model)
{
//Do logic
return CurrentTemplate(model);
}
}
If you have a template called News for example and you want it to hit your HomeController you need to add this:
public ActionResult News(RenderModel model)
{
//Do logic
return CurrentTemplate(model);
}
It's also possible to disable alt template when you're using internal redirect. It's the internalRedirectPreservesTemplate attribute in the umbracoSettings.config file.
In your situation it might be better to disable the alt template if you don't need it. So just set the attribute to false in umbracosettings.config. Restart the website and after that it should go to the 404 page.
using template name in the URL shows error
Hi guys,
I am currently working on the 404 page not found and I noticed that if i have a Template name in the URL, it shows 500 Server error, instead of page not found.
e.g. http://SomeUrl.com/template1
I was expecting this will throw an 404 but it didn't, instead i got this error message
Since this is .net MVC, i thought it will goes through HomeController, as defined in the RouteConfig.cs. But it seems to bypass this configuration.
Does anyone have any idea how to show 404? instead of error message?
Thank you
Shinsuke
Hi Shinsuke
What exact version of Umbraco are you using? It might be a bug.
/Jan
I'm using 7.1.8
It looks like same error with this one http://issues.umbraco.org/issue/U4-2691
But it said it was fixed in version 6.2?
Hello,
It will go to the HomeController, but when you're using an alt template it will go to a different ActionResult. For example if this is your HomeController:
If you have a template called News for example and you want it to hit your HomeController you need to add this:
It's also possible to disable alt template when you're using internal redirect. It's the internalRedirectPreservesTemplate attribute in the umbracoSettings.config file.
Jeroen
Hi Jeroen,
Thank you for your reply, I did try creating
But this didn't work. I even created a HomeController constructor but it didn't go through there either.
However i did look up how to disable "alt template" and found a solution here
http://our.umbraco.org/forum/templating/templates-and-document-types/50392-How-to-disable-TemplateName-altTemplate-behaviour-in-v6
I didn't know about the "alt template" and how it worked, till you mentioned it in your post
Thank you
Shinsuke
In your situation it might be better to disable the alt template if you don't need it. So just set the attribute to false in umbracosettings.config. Restart the website and after that it should go to the 404 page.
Jeroen
Hi Jeroen,
I did try set the value of "internalRedirectPreservesTemplate" to false, and restarted the web server but that didn't disable the alt template.
I think its because in my scenario, people are coming to this page from external reference. such as google search or old EDM links?
It only disables alt template if the page has an internal redirect. Otherwise the solution from the other topic probably works.
Jeroen
is working on a reply...