tags:

views:

16

answers:

2

I have a lot of broken links that are not being logged. Is there a way to setup IIS to send them through ASP.NET so that my normal 404 logging routine catches them?

+1  A: 

You could use the host MVC on IIS 6 hack method. Basically, setup a wildcard .* mapping in IIS and have the aspnet_isapi.dll handle this request, which is the same as having .NET handle all request. You may experience a performance decrease (probably minimal), but it should hit your logging routine.

IIS 6 Hack

Tommy
+1  A: 

If you are using IIS7 you can use the httpErrors configuration element. What this does is (after the request has been handled) it checks the response code that has been pushed to the output, and allows you to intercept calls, such as:

<httpErrors existingResponse="PassThrough">
    <remove statusCode="404" />
    <error statusCode="404" responseMode="ExecuteURL" path="/PageNotFound.aspx" />
</httpErrors>

It's a lot like ASP.NET's customErrors mechanism, with the exception of being processed later in the pipeline. In the above example, I'm telling it to execute the URL /PageNotFound.aspx when it encounters a 404. You have to be careful though, because if you send a 404 from the PageNotFound.aspx page (typically you would!), it can get caught up in a cyclic redirect. To get round this, we add the following attribute:

existingResponse="PassThrough"

What this does is to determine if the current response already has a body, and if so, pass it along (don't process the status code).

I posted this on my blog a while ago: http://www.fidelitydesign.net/?p=21

Hope that helps :)

Matthew Abbott
Sounds like it is time to upgrade
Jonathan Allen
There are so many reasons to upgrade to IIS7, but don't forget, you can't have IIS7 without Windows Server 2008, so it's a full server upgrade ;)
Matthew Abbott