Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 Redirecting for non aspx pages

I am using the web.config code below to redirect requests to missing pages to a 404 error handling page:

<customErrors mode="On" defaultRedirect="404.aspx" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="404.aspx"/>
</customErrors>

It works fine when I look for pages such as "missing.aspx" but it does not work for pages without the ".aspx" extension such as "missing.asp" or just "missing". When it does not work, it just loads a standard IIS 7.5 error page.

What am I doing wrong? I am using .net 4. I noticed other people asking the same question but they didn't get an answer.

Thanks!

like image 691
Osprey Avatar asked Jun 15 '12 06:06

Osprey


1 Answers

Add the following to the Web.config:

<system.webServer>    
    <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL" >
      <remove statusCode="404" />
      <error statusCode="404" path="/Default.aspx" responseMode="Redirect" />
    </httpErrors>
  </system.webServer>

I took Osprey's code, and added responseMode="Redirect" to fix the problem of just displaying the source code of the page.

like image 111
Matt G Avatar answered Oct 16 '22 14:10

Matt G