Sam....thanks for your suggestion on the IHttpModule Dispose, however I am
99% certain it is NOT being driven. I have even tried "throwing an
exception" in the Dispose....and NOTHING. Yet, I can force an application
recycling by changing the web.config....and I will see a new INIT being
driven when I do this.
Code follows...
using System;
using System.Web;
using System.Web.Hosting;
using System.Collections;
using System.Text;
using System.IO;
public class HttpModuleTrace : IHttpModule
{
~HttpModuleTrace()
{
TraceIt("Finalizer");
}
public void Init(HttpApplication application)
{
TraceIt("Init");
application.BeginRequest += (new
EventHandler(this.Application_BeginRequest));
application.EndRequest += (new
EventHandler(this.Application_EndRequest));
application.Disposed += (new EventHandler(this.Application_Disposed));
}
public void Dispose()
{
TraceIt("Dispose");
}
private void Application_BeginRequest(Object source, EventArgs e)
{
TraceIt("Application_BeginRequest");
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.Write("<h1><font color=red>HelloWorldModule:
Beginning of Request</font></h1><hr>");
}
private void Application_EndRequest(Object source, EventArgs e)
{
TraceIt("Application_EndRequest");
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.Write("<hr><h1><font color=red>HelloWorldModule:
End of Request</font></h1>");
}
private void Application_Disposed(Object source, EventArgs e)
{
TraceIt("Application_Disposed");
}
private string GetTraceFilePath()
{
System.Web.HttpContext http = System.Web.HttpContext.Current;
return http.Request.PhysicalApplicationPath + "HttpModuleTrace.txt";
}
private void TraceIt(string TraceText)
{
using (StreamWriter sw = new StreamWriter(GetTraceFilePath(), true,
System.Text.Encoding.UTF8))
{
sw.WriteLine(DateTime.Now.ToString("d-MMM-yyyy HH:mm:ss.fff") +
" - " + TraceText);
sw.Flush();
sw.Close();
}
}
}