Try our conversational search powered by Generative AI!

404 handler in 4.60 using friendly URLs

With EPiServer 4.60 in friendly URL mode, I'm trying to get a proper 404 solution in place when invalid URLs are entered so that a valid 404 HTTP status code is returned and a custom page is displayed. I've tried using the Application_Error event in Global.asax.cs but it does not appear to fire when in friendly URL mode. Does anyone know of a way to get this to work correctly? Currently EPiServer does return a 404 HTTP status code but displays its own error page. Thanks.
May 18, 2006 12:01
Have you tryed to change the /util/Notfound.aspx file to a custom .aspx error page? You can read how to do this in this FAQ:
May 18, 2006 13:22
Yes I have tried this method. If I use a friendly URL style address in the URL for error code 404 in IIS I get the error message "The system cannot find the path specified." when I try to access any page in the site regardless of whether it exists or not. If I try and use a URL of the style /templates/page.aspx?id=34 then I get the following error for any page: [EPiServerException: The current template "/templates/page.aspx" does not match the specified page type file "/default.aspx"] I could use a page that is not an EPiServer page (i.e. just a standalone aspx) but then I lose the site look and feel without reconstructing it for a single standalone page. The behaviour appears to be different between using friendly URLs and not which is where my confusion is coming from.
May 18, 2006 14:09
Not having checked if you're actually allowed to have a queryparamter in the 404 url in IIS, I suspect that IIS is removing it. So, "/templates/page.aspx?id=34" may actually be just "/templates/page.aspx" when it reaches your site. EPiServer sees the missing id, and automatically loads the start page instead. However, there is a security check in the template, to avoid loading pages using templates that they where not designed for. So, the start page page type has been configured to use /default.aspx, but is now loaded using /templates/page.aspx. As a side note, I'd avoid having the 404 page as a page in EPiServer. There might be other reasons for the 404 page showing, like a missing image, and that will actually load that 404 page, even though the user cannot see it. Now, what happens if your 404 page in EPiServer refers to an image that is deleted from the server? :-) Last, the 404 page _should_ have another look and feel than the rest of the site. The user needs to understand that something out of the ordinary has happened. I've seen 404 pages that had so much noise that it took me a long time just to realise I was in the wrong place! /Steve
May 18, 2006 20:26
>>Now, what happens if your 404 page in EPiServer refers to an image that is deleted from the server? YES - please tell me I was just about to post this as a question - i have this problem after going to UFS on 4.51. I dont get my custom error page but just the standard episerver error page. Why? /John
May 19, 2006 9:39
Hi John, I assume you've checked the 404 setting in IIS. What I actually ment by my question was this: What if your custom 404 page (which is a normal EPiServer page) refers to a missing image (a wrongly typed spacer.gif url for an example)? Well, that will trigger the server to return yet another 404 page. So, you'll actually get two 404 instead of just one. Not a big deal I hear you say, the extra performance penalty will be negligible in the long run. Yes, it might, as long as the browser stops at that point. Using dynamically loaded images, I've had this almost taking down the server, as each request ended up in a loop, asking for more and more 404 pages. That is why I always tell people to be very careful about the contents, design and functionality of the 404 page. I have yet another question :-) How could someone start a Denial of Service attack on your server if you have a dynamic 404 page (a normal EPiServer page)? /Steve
May 22, 2006 19:45
Hi Steve! which 404 setting are you talking about? I have set my custom 404 error page to a standard aspx page and everything works fine until as you say the user mistypes a url to an image or document. This wasnt a problem until we changed to UFS. My custom page is an enhanced version of the standard episerver error page with more fields and performs the same function - to email an error report. Are you saying I need to capture the 404 on that page? I read your message 5 times and Im still non the wiser... /John
May 22, 2006 22:29
I was speaking in general terms, about what to do and what not to do when it comes to making your own 404 handlers. The thing I'm warning about is to point the 404 handler in IIS (custom errors tab) to a standard EPiServer page (like /templates/page.aspx?id=1234). I can see why people want to do this, as this would let an editor write the content for the 404 page, updating it with the new urls for common 404 paths. About your particular case, I'm not quite sure what the problem is, but I know there are different type of missing urls that you cannot handle by having your own 404 page. Could you explain your troubles in some more deail? What type of url that does not work, and what page you get instead ("Page does not exist" or "Page could not be loaded" - there is an important difference). /Steve
May 22, 2006 23:52
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.