Technical support This forum is closed.
Version 1.x > Technical support > Handling 404 View modes: 
User avatar
Member
Member
trint99 - 9/14/2006 6:06:02 PM
   
Handling 404
Using version 1.9.2405.

Currently, any request to a page that is not part of the Kentico tree results in the default page being rendered. If a request for a nonexistant page comes it, we'd like to handle it with a custom 404 page rather than redirecting to the home page. How is this done?

User avatar
Member
Member
davidmohara - 9/15/2006 2:40:17 PM
   
Re: Handling 404
This is actually a function of .NET and not Kentico as far as I know. Error handling can be done best in <a href="http://www.aspnetresources.com/articles/CustomErrorPages.aspx">this way</a>.

User avatar
Member
Member
trint99 - 9/15/2006 9:52:50 PM
   
Re: Handling 404
Using .NET's customErrors will not take care of all my problems. It seems that IIS handles 404 errors without passing them to .NET when the url does not end in .aspx. We're using friendly URLs in Kentico, so that is the case for most of our pages.

Also, I know that Kentico is catching at least some 404 errors.

Example:
I have a Kentico document at http://mysite.com/Help/ContactUs.

If I navigate to http://mysite.com/Help/ContactMe (incorrect Friendly URL), I get an IIS "white page" 404 error.

If I navigate to http://mysite.com/Help/ContactMe.aspx (a file that does not exist) I am redirected to the Kentico site's default page. This happens regardless of whether I have customErrors set to On or Off.

User avatar
Guest
admin - 9/18/2006 10:45:58 AM
   
Re: Handling 404
Hello,

unfortunately, I cannot reproduce such behavior. If I use 1.9a/CS05 version with CorporateSite sample and go to /Newsx.aspx (invalid URL), I get the standard "The resource cannot be found." error.

The only thing that comes to my mind is this: If you have two pages:

/Help (page/menu item with page template)
/Help/ContactUs (page/menu item with page template)

and go to /Help/ContactX (invalid URL), the system automatically uses the page template of /Help to display the content.

Best Regards,

User avatar
Member
Member
trint99 - 9/19/2006 11:00:29 PM
   
Re: Handling 404
Nope. I don't have a page for Help. Help is a folder. I have changed the folder objects to allow images, pages, and articles to be children. Maybe that has something to do with it.

http://light-spark.com/share/KenticoTree.gif

I've noticed that the default behavior when you navigate to a folder is to redirect to the home page. Could it be that, because I have pages (menu items) as children of folders, when the page is not found it tries to render the nearest parent (the folder) which then redirects to the home page?

Why pages in folders...
The reason I want to use folders is to allow for a more intuitive arrangment of pages in the tree. We've already abandoned the idea of using Kentico's navigation controls becase in our nav scheme we have one page that appears in many places in the navigation. It turns out to be much easier to have our nav be an article that is manually edited. We just need that kind of freedom in our navigation. (This way the marketing guys can arrange it however they want and it doesn't have to rely on the actual pages being moved around.)

User avatar
Guest
admin - 9/20/2006 7:58:46 AM
   
Re: Handling 404
Thank you for the details. Unfortunately, we still cannot reproduce the issue. Even if we place the page under a folder, both existing and non-existing URLs work correctly.

Best Regards,

User avatar
Member
Member
davidmohara - 1/22/2007 4:25:02 PM
   
Re: Handling 404
My apologies for dragging this issue back up but I have run into the same issue. Here is my current structure:

Home
Home | Content <-- This is a folder not a page
Home | Content | MyPage <-- This is a page not a folder
Home | Products <-- This is a page not a folder

Here are the behaviors that I am seeing:

http://localhost/Website/ <-- Normal homepage
http://locahost/Website/Products <-- Normal page
http://localhost/Website/Products/junk <-- Redirects to standard 404 page (per IIS)
http://locahost/Website/Content/MyPage <-- Normal page
http://localhost/Website/Content/ <-- redirects to Home page

The last one is the problem that I'm having. I would like for it to redirect to the standard 404 page instead. Why is this not behaving as expected?? Can you point me to how to fix it??


Thanks,
Dave O'Hara

User avatar
Member
Member
davidmohara - 1/23/2007 3:29:58 PM
   
Re: Handling 404
Actually, I was able to find this issue after a little digging in code. I have not used 2.0 yet so this may have changed for that version but I thought I'd post the fix in case anyone else wants this change. Also, the solution that I created allows for the defaulted URL to be changed via the CMSDesk web.config to give it more flexibility.

In the UrlRewritingEngine project, navigate to line 31 of URLRewriter.cs. It should look like this:
HttpContext.Current.Response.Redirect("~/");

Replace that line with the following:
string redirectUrl = "~/";<br/>
if ( ConfigurationManager.AppSettings.Get( "CMS404Path" ).Length > 0 )
{
redirectUrl = ConfigurationManager.AppSettings.Get( "CMS404Path" );
}
HttpContext.Current.Response.Redirect( redirectUrl );

Now, when you add the node "CMS404Path" to the web.config, your site will redirect there instead of the home page when someone attempts to navigate to a folder instead of a page.

Please let me know if you have any problems or questions.


Thanks,
Dave O'Hara

User avatar
Guest
admin - 1/24/2007 10:21:52 AM
   
Re: Handling 404
Hi David,

Thank you for your post. Unfortunately, I cannot find such code on the line 31. The only similar code is this:

// test if document exists - if yes, redirect user to the root
if ( DocExists(fullAliasPath, connectionString) )
{
HttpContext.Current.Response.Redirect("~/");
}

Could you please write me which version (build number, C#/VB.NET, 2003/2005) you are using?

Thank you.

Best Regards,

User avatar
Member
Member
davidmohara - 1/24/2007 2:22:14 PM
   
Re: Handling 404
Petr,

My apologies, I should have included that in my post. I am using the 2005 C# version of 1.9 - the build number is not referenced since we purchased the source option and are building it ourselves. The code that you posted looks like the same code that I was referring to. Does my fix create any issues that you can see?? We have not run into any but it's always good to ask. :)


Thanks,
Dave O'Hara