I'm having trouble using the HTTP Status codes from a managed http module in asp.net on different versions of IIS.
IIS 5.1
200 127.0.0.1 http://localhost/httpModuleTest/default.aspx 127.0.0.1 10/16/2009 9:49:27 AM
200 127.0.0.1 http://localhost/httpModuleTest/notfound.aspx 127.0.0.1 10/16/2009 9:49:32 AM
IIS6
200 127.0.0.1 http://iis6.example.com/Default.aspx 127.0.0.1 10/16/2009 9:51:57 AM
200 127.0.0.1 http://iis6.example.com/missing.aspx 127.0.0.1 10/16/2009 9:52:03 AM
IIS7
200 127.0.0.1 http://iis7.example.com/default.aspx 127.0.0.1 10/16/2009 10:02:58 AM
404 127.0.0.1 http://iis7.example.com/missing.aspx 127.0.0.1 10/16/2009 10:03:04 AM
Basically for anything i've tried below IIS7 returns 200 OK no matter what. IIS7 reacts correctly or rather asp.net reacts correctly on IIS7 and returns the expected status code. Is there any way of getting the correct status code from IIS when not running 7.0?
Sample code:
public class SampleHttpModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_EndRequest(object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
string logFile = application.Server.MapPath("~/log.txt");
StreamWriter writer = File.AppendText(logFile);
writer.WriteLine(String.Format("{0} {1} {2} {3} {4}", context.Response.StatusCode, context.Request.UserHostName, context.Request.Url, context.Request.UserHostAddress, DateTime.Now));
writer.Close();
}
#endregion
}