12 Dec 2011

Adding a Custom 404 Page with Sitefinity

Category:

It's always annoying when you mis-type a URL, or click on a long-dead link to be confronted with a horrible error message:

.Net 404 error page

It looks unprofessional (especially if you are a web development company), scary and leaves the visitor with nowhere to go. Much better would be your own customised 404 page, gently directing the site visitor to a more appropriate place. To get this working in a Sitefinity site you need to do three things:

1. Create a 404 page in Sitefinity. You can just make a plain, unadorned page but this "not found" area is a great place to funnel customers back to where they need to go (or where you'd like them to go!). There's lots of articles around on how to make use of your 404 page, such as this 404 guide from GetElastic.

If you have no other ideas, just add contact links, top-level navigation links or links to social media. Call the page whatever you like but for the purposes of this guide I'll pretend you called it "404.aspx".

2. Change the web.config. Add the following line to the web.config file in the custom errors section:

<error redirect="/404.aspx" statuscode="404"></error> 

This will capture some of the errors. Try visiting yoursite.com/SomeNonexistentPage.aspx and you'll be presented with your custom 404 page. Great!

No time to party yet though - if you knock the ".aspx" off the end of your address, you'll get yet another horrid message:

IIS 404 error page

What's happened here is we've stopped the first kind of error message which is generated by .Net. It's now bounced down the line to IIS which has also thrown it's own error-handling page. To get round this one...

3. Redirect 404 errors to your Sitefinity page. Open your site in IIS and look for the following icon:

IIS .Net Error Pages Icon

You should be presented with the following dialogue box:

IIS Add Custom Errors

In the Status Code type "404" and in Absolute URL the full link to your error page e.g. "http://www.yoursite.com/404.aspx".

OK this screen and try it again. You should be getting your custom 404 page in all situations now! Very handy.

Go Back

Please enter your details and we will aim to call you back the same day.