404 handling is better in .NET.

As some of you guys run some pretty pretty sites, I wanted your feedback on how 404s work. I've tried many different settings with .Net but could never get it to do it right. I seem to be getting some sort of redirect or fake title that was never 404. This is a real pain because search engines never get the right feedback and still click on these pages even though they no longer exist. This in turn means that I am getting error messages for pages that I know no longer exist. I'm also quite confused about the fact that some requests are handled by .Net and some are handled by IIS.

My current setup looks like this: IIS7, ASP.Net 3.5 App. I have a custom web.config setup error pages page to handle 404 using the new redirectMode = ResponseRewrite property, redirecting to the html error page. IIS is configured to handle 404s and send them to the same html page. Elmah is determined to also report any such issues via email.

Now when I try the following URL http://www.severnside.com/document.aspx (a page that doesn't exist). Net handles the error and shows a 200 response. Obviously it should be a 404. When I try http://www.severnside.com/document I get the correct 404, but the error was handled by IIS. Is it possible to have .Net handle this error too much for Elmah to pick up the error?

It would be great if I could get an idea of ​​the settings others are using to properly manage a scenario like this.

thank

+2


source to share


1 answer


Instead of using a static html page, you can use a dynamic page that will set the correct status code:

404.aspx:

<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
    Response.StatusCode = 404;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Not found
    </div>
    </form>
</body>

      



web.config:

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

      

+8


source







All Articles