Nannette Thacker ShiningStar.net

ASP.net Web Application Development

Sponsors

News

See all Blog Posts by Nannette.

Nannette Thacker, consultant and owner of Shining Star Services LLC, specializes in development of custom dynamic database driven web applications utilizing ASP.net technologies. Nannette has been developing ASP sites since 1997. Nannette has written numerous articles on web development techniques and tutorials.

Nannette is the owner and developer of ChristianSinglesDating.com.

 Subscribe in a reader





View Nannette  Thacker's profile on LinkedIn

Custom Error Pages and 404 Page Not Found Error Web.Config Setup

When receiving 404 page not found errors on your web site, and you wish to direct users back to your home page, you need to setup two things in your web.config to handle all instances.

If you use IIS7 and go to the Error Pages section and setup the 404 error to "Execute a URL on this site" and have it go to : /default.aspx and select OK to save the changes, it will update your system.webServer section of your web.config file and add these lines:

<httpErrors>
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" 
path="/default.aspx"
responseMode="ExecuteURL" /> </httpErrors>

This will redirect any pages such as http://www.shiningstar.net/test with no file extensions. But if the URL sends the user to a page with a known file extension, they will still be taken to the 404 error page.

So if you want to redirect a page such as http://www.shiningstar.net/test.aspx you will also need to add custom error handling to your system.web section of your web configuration file:

<customErrors mode="RemoteOnly" 
defaultRedirect="~/ErrorPages/Error.aspx"> <error statusCode="404" redirect="~/default.aspx"/> </customErrors>


The 3 options for the mode are: Off, On, and RemoteOnly. To test your error handling locally, change the mode to "On." Once you've tested it, change it to "RemoteOnly" which will still allow you to receive descriptive errors when developing locally.

May your dreams be in ASP.NET!

Nannette Thacker


View Nannette  Thacker's profile on LinkedIn

Comments

Castors said:

very nice information.

# January 16, 2012 1:34 AM

Anonymous said:

Thanks! Really helpful.

# October 15, 2012 10:55 PM

Rockrocky said:

Thank you for sharing this information with us. I really like it. and I really hate it :D

# February 26, 2013 12:41 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)