ASP.NET - Making a comprehensive 404 page

When I was doing a project at work I was tasked with setting up a 404 page for an ASP.NET website, and generally just making sure there wasn't any conflicts. As I am normally a PHP developer I figured it wouldn't be too hard as its very easy to assign a 404 error to a certain file with Apache using a .htaccess file. I was about to be very put off by how difficult it was to actually get this working, and further more, how under-documented it was online. So I decided to write up a very quick and easy instruction manual.

This does assume access to the main server, for people on shared hosting you will probably have something in your cpanel equivelant which will assign a 404 page for you.

1. Place the follow code into a file called web.config inside your base directory of your website (normally c:\inetpub\wwwroot\)


 defaultRedirect="ErrorPage.aspx" mode="On">   
statusCode="500" redirect="servererror.aspx" />
statusCode="404" redirect="filenotfound.aspx" />
statusCode="403" redirect="AccessDenied.aspx" />


2. Then open up the following settings in the IIS manager:

start > programs > IIS manager

  • Then on your website name on the left hand menu right click and goto 'properties'.
  • A dialogue window will popup and there will be a tab at the top called 'custom errors'
  • On this tab there will be a list of pages, scroll down to the 404 error select it, then click on 'edit properties'
  • A box will popup, and this part is very under-documentated. You need to select URL from the dropdown and then enter the url.
  • REMEMBER: the url you enter needs to just be my404errorpage.aspx you do not need a full url, only a relative one to the base of the websites root directory.

I hope this helps if anyone manages to get a hold of this page on Google. Let me know of any inaccuracies through the comments section.


Buy me a beer or a book?

amazon PayPal - The safer, easier way to donate online!

Free Downloads