Hi gilad, thanks for the suggestion. But wouldn't that redirect the user to the 404 page? I'd really like to just display the 404 page without redirecting.
At this point, IIS should take over and display the proper 404 page. (And as a side note, if you did NOT want IIS to take over, you would precede these lines above with Response.TrySkipIisCustomErrors=true;
Just be careful using the path "/404/" if you are using extensionless (directory) URLs, as this bug here may cause additional frustration. (It did for me! I now use "/error404" for my own.)
I cannot find a proper way of handling 404 without changing the web.config. this is already in production and if i change the PassThrough value i would have to test the entire site again.
I'm trying to figure out how to make this work without using the customErrors in the web.config as well. I want to use the error404 settings in the /config/umbracoSettings.config. Is there a way to throw an HttpException and have umbraco kick in and send me to the culturally appropriate 404 page as configured in the /config/umbracoSettings.config?
For example, what if I wanted to put something like this in a view?
@inherits UmbracoTemplatePage
// logic here to get some values from query string
//...
if(myVal == null)
{
throw new HttpException(404, "Page not found");
}
This is what I have in my /config/umbracoSettings.config that I want to be able to leverage:
Do I have to make one of those custom ContentFinders to get this working? I'm guessing that's how umbraco is implementing its error404 functionality. Is that right?
Display 404 page from razor code
I have a template which displays a page list items, and uses a modified version of the paging script coming with Umbraco.
The script works by retrieving the current page to display from a parameter in the url, typically ?page=xx
It is possible to call this url with invalid page numbers, and I'd like to return the 404 page for those requests.
How can I display the 404 page from within razor code? I don't want to redirect the user, just display the 404 page.
I tried
but this results in macro errors.
Hii Markus
You can do something like this :
Hope that help.
Cheers.
Hi gilad, thanks for the suggestion. But wouldn't that redirect the user to the 404 page? I'd really like to just display the 404 page without redirecting.
I believe if you have CustomErrors enabled in your web.config, all you need to do is call the following:
Response.StatusCode = 404;
Response.StatusDescription = "Not Found";
At this point, IIS should take over and display the proper 404 page. (And as a side note, if you did NOT want IIS to take over, you would precede these lines above with Response.TrySkipIisCustomErrors = true;
Best of luck!
Hi Funka!
I tried your suggestion, and it worked as soon as I added the following to the web.config (obviously...):
Thanks!
Excellent, glad you got it working!
Just be careful using the path "/404/" if you are using extensionless (directory) URLs, as this bug here may cause additional frustration. (It did for me! I now use "/error404" for my own.)
is there another way of doing this if we have: https://our.umbraco.org/wiki/install-and-setup/configuring-404-pages in our web.config?
I cannot find a proper way of handling 404 without changing the web.config. this is already in production and if i change the PassThrough value i would have to test the entire site again.
I'm trying to figure out how to make this work without using the customErrors in the web.config as well. I want to use the error404 settings in the
/config/umbracoSettings.config
. Is there a way to throw an HttpException and have umbraco kick in and send me to the culturally appropriate 404 page as configured in the/config/umbracoSettings.config
?For example, what if I wanted to put something like this in a view?
This is what I have in my
/config/umbracoSettings.config
that I want to be able to leverage:Do I have to make one of those custom ContentFinders to get this working? I'm guessing that's how umbraco is implementing its error404 functionality. Is that right?
Hi Mark Bowser
Did you find a way to do it? I really need the same functionality
Alex
is working on a reply...