Best Practices for 404 pages with Composite

Topics: General, Troubleshooting
Jul 7, 2011 at 7:50 PM

Because Composite C1 handles URL rewriting, what's the best way to handle 404 pages. Normally, I'd just create a page that includes the sitemap and reference it in the web.config. However, I noticed that there's a FileNotFoundFandler.ashx. So, are there any implications to implementing a custom 404 page without breaking any functionality in Composite C1.

I'd like to have something like this: http://searchenginewatch.com/doesnotexist

Jul 7, 2011 at 8:09 PM

Just replace the FileNotFoundFandler.ashx with a file of own choosing... its not being used for anything crucial in C1.

Jul 7, 2011 at 8:22 PM
Edited Jul 7, 2011 at 8:53 PM

Cool. That's what I wanted to know. :-)

Now to see how I can get a Composite C1 Page (to retain my layout in C1) to return a 404. :-)

Jul 7, 2011 at 8:30 PM

btw, if youre using 2.1.3 you can set the 404 page per host/domain and not just system wide

Jul 8, 2011 at 8:34 PM

Is it possible to do 404 pages like this?

http://weblogs.asp.net/paxer/archive/2010/05/31/asp-net-http-404-and-seo.aspx

Ideally, I'd like to return a 404 without a 302 redirect. 

I've added this to Global.asax but it doesn't seem to work:

protected void Application_Error(object sender, EventArgs e)
            {           
                Exception ex = Server.GetLastError();
                if (ex is HttpException)
                {
                    if (((HttpException)(ex)).GetHttpCode() == 404)
                        Server.Transfer("~/404.html");
                }
                // Code that runs when an unhandled error occurs
                Server.Transfer("~/GenericError.htm");
    
            }

Coordinator
Jul 8, 2011 at 9:35 PM

>> Ideally, I'd like to return a 404 without a 302 redirect. 

That's the way it works in beta. I added a {*} url route, to be executed last, so it handles all not handled requests:

...

routes.Add("c1 404 route", new PageNotFoundRoute());
...

and then Server.Transfer() (if IIS is running in integrated mode)
If you want to check the code, start from class Composite.Core.Routing.Routes

 

Or you can try the beta version, that's exactly how it works there.  When you add a "hostname binding", you can specify a 404 page (http://docs.composite.net/C1/Getting-started/Configuration/UrlConfiguration.aspx). Upgrade description may seem to be long, but it shouldn't take more than 15 minutes to perform the upgrade.

Jul 11, 2011 at 4:09 PM

You have seriously made my day. The combination of Extensionless URLs, easy to implement 404 pages, and pathInfo enhancements in 2.1.3 are the missing piece of the puzzle for me. One question... how stable is the 2.1.3 release? I'm going to to test it... but is it ready for production sites?

Coordinator
Jul 12, 2011 at 8:21 AM

>> One question... how stable is the 2.1.3 release? I'm going to to test it... but is it ready for production sites?

We haven't done any extensive testing, which THE requirement for recommending it, so it's not an officially recommended version

There's a new bug with javascript insertion (related to http://compositec1.codeplex.com/discussions/260547) , which I'll try to fix to day. Other than that I'm not aware of any new "show stopper" bugs

Coordinator
Jul 12, 2011 at 9:01 AM

>> There's a new bug with javascript insertion

Fixed that one, it was present in previous versions, and shouldn't be relative to the code you used in http://compositec1.codeplex.com/discussions/260547, so - no problems there

Jul 12, 2011 at 11:43 PM
Edited Jul 13, 2011 at 12:01 AM

Thanks napernik.

Two questions:

  1. Can a 404 page be a C1 Page? 
  2. Is there anything that needs to be configured in Web.Config (removing entries, adding entries, etc.)

I have made a 404 page in my C1 tree and called the Url Title not-found and /not-found as the Friendly Url

I can access it directly with Extensionless Urls and the home page url title "blank" like so [domain]/[language]/not-found 

In my URL Configuration, I have set up the 404 page to point to C1 Page "Friendly Url" /not-found and it returns a 302.

I have also tried specifying the 404 page to be: /en/not-found figuring it doesn't work with friendly URLs and it still returns a 302. 

I have upgraded my test site to 2.1.3 so... I just wanted to confirm that the 404 that uses Server.Transfer for 404 pages is for a newer Beta than 2.1.3, right?

Coordinator
Jul 13, 2011 at 8:14 AM

>> Can a 404 page be a C1 Page?

Yes

>> Is there anything that needs to be configured in Web.Config (removing entries, adding entries, etc.)

no (except for the steps in the upgrade procedure)

>> ...  I have set up the 404 page to point to C1 Page "Friendly Url" /not-found and it returns a 302.

Check your IIS, the related AppPool should be running in "integrated" mode for Server.Transfer() to work. If you host your site in Visual Studio or IIS6, it won't work.