views:

186

answers:

1

I have some broken links on my site, and will keep having new ones on regular basis. How do i write a centralized code in web.config or something for 404 then redirect to home page? I am using aspx, vb.net and IIS7

+3  A: 

In the web.config you can have a section as follows -

<customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx">
 <error statusCode="404" redirect="/" />
</customErrors>
Yossi Dahan
Just FYI, by default .Net will actually send a 302 Redirect instead of a 404 Page Not Found. It might not matter to you but it does affect search engines. To change it set the redirectMode of the customErrors to ResponseRewrite. Here's more on it:http://chrishaas.wordpress.com/2009/04/22/true-asp-net-and-iis-404-errors/
Chris Haas