2

I have an custom IHttpModule that handels all available events and logs the HttpContext.Current.Response.StatusCode to a file.

My web.config does not contain any other module in <httpModules> so all errors are promoted to the browser.

Although the Browsers shows a 404, the log file is full of 200 (Ok) entries and not a single 404.

What am I missing?


Update

An Url ending with .aspx does have a 404 StatusCode in the PreSendRequestHeaders event, but Urls wending with .pdf for example show StatusCode 200 in all events?!

3 Answers3

0

A bit late to the party. Try removing preCondition="managedHandler" in web.config for your module

MichaelD
  • 8,377
  • 10
  • 42
  • 47
0

I had the same problem and I resolved it casting the current exception in the handler in HttpException. Then, you can get the Http error code.

Exception exception = HttpContext.Current.Server.GetLastError();
HttpException httpException = exception as HttpException;
if (httpException != null)
{
    int httpCode = httpException.GetHttpCode();
}

Source : http://www.digitallycreated.net/Blog/57/getting-the-correct-http-status-codes-out-of-asp.net-custom-error-pages

Hope it helps :)

Pedro
  • 3,511
  • 2
  • 26
  • 31
0

Is your module actually running when there's a 404?

Have you attached a debugger to the application with a breakpoint in the module - does it get hit at that when you request a non-existant .aspx page? Does it get hit when you request a non-existant file or directory?

Depedning on the set-up of IIS, it's possible that ASP.NET isn't getting a look in with these errors - it's not going to handle a request for somepage.html for example, or missing.gif.

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • Thank you for the hint with the .aspx. I updated the question. Module is running: it logs a bunch of "Eventname+Status+Url" lines. –  Jun 09 '09 at 10:20