i have started a topic on this a while ago, but the suggested solution is a pain:
I want to deal with only one 404 handler and preferably this is the one configured within the IIS, since i want to handle error outside of umbraco as well (e.g. for classic .asp pages or download files, which are not handled by umbraco). I came to the conclusion that my target of customization would be the umbraco requestHandler, but i have no clue how to raise an IIS 404 error from there if currentPage is null. Any ideas?
I have found a working solution, which requires the umbraco requestHandler to be modified and raises a IIS error, so i can handle all errors using one single error page. I will post my solution tonight, as i have to get my daughter from daycare now.
So, a little late, but here is my - simplified (using a custom asp.net error page) - solution for 4.0.21:
requestHandler.cs
In requestHandler.cs (part of the source distribution and located in the umbraco.presentation project) you have to comment out the content (and only the content, not the if-statement itself) of the following if-statement appearing in the constructor:
if (currentPage == null)
and put something like this into this if statement:
HttpException ex; ex = new HttpException(404, "Requested document was not found"); throw ex;
This raises a HttpExcepton with 404 error code that will be handled by IIS configured error management.
web.config
Of course you have to set up the by modifying the "customErrors" element of your web.config like this:
How to raise umbraco 404 error in IIS
Hi,
i have started a topic on this a while ago, but the suggested solution is a pain:
I want to deal with only one 404 handler and preferably this is the one configured within the IIS, since i want to handle error outside of umbraco as well (e.g. for classic .asp pages or download files, which are not handled by umbraco). I came to the conclusion that my target of customization would be the umbraco requestHandler, but i have no clue how to raise an IIS 404 error from there if currentPage is null. Any ideas?
Thanks,
André
I would suggest you make a plain staic 404 handler for non aspx pages. To handle this in a requestHandler you need to route all requests through .NET.
Hi Chris,
I have found a working solution, which requires the umbraco requestHandler to be modified and raises a IIS error, so i can handle all errors using one single error page. I will post my solution tonight, as i have to get my daughter from daycare now.
Cheers,
André
So, a little late, but here is my - simplified (using a custom asp.net error page) - solution for 4.0.21:
requestHandler.cs
In requestHandler.cs (part of the source distribution and located in the umbraco.presentation project) you have to comment out the content (and only the content, not the if-statement itself) of the following if-statement appearing in the constructor:
and put something like this into this if statement:
This raises a HttpExcepton with 404 error code that will be handled by IIS configured error management.
web.config
Of course you have to set up the by modifying the "customErrors" element of your web.config like this:
and add the errorpage's virtual path to the "umbracoReservedUrls" appSettings element, so umbraco won't try to handle your errorpage.
Your error page
Your error page holds all your your logic to set the appropriate error codes and redirection targets. Basically it may looks like this:
So, that's it.
is working on a reply...