G
GWiz
All,
I am trying to write a multi-threaded HTTP module that handles the
OnBeginRequest and logs it. What I am trying to do is to offload the
logging to another thread which will allow the http module to release
the OnBeginRequest.
The issue that I have is that I keep on getting "Request is not
available in this context" exceptions.
The following is the code I am using:
using System;
using System.Web;
public class ProcessRequest
{
public HttpApplication HttpRequest;
public void ProcessingThread()
{
try
{
string sRequestUrl;
if (HttpRequest.Request!=null)
{
sRequestUrl=HttpRequest.Request.HttpMethod;
System.Diagnostics.Debug.WriteLine(sRequestUrl);
}
}
catch (System.Exception ex)
{
throw ex;
}
}
}
public class HttpRequestLogger : IHttpModule
{
protected System.Collections.Queue oHttpRequestQueue= new
System.Collections.Queue();
protected bool bModuleRunning =false;
public HttpRequestLogger()
{
}
// In the Init function, register for HttpApplication
// events by adding your handlers.
public void Init(HttpApplication application)
{
application.BeginRequest +=
(new EventHandler(this.Application_BeginRequest));
application.EndRequest +=
(new EventHandler(this.Application_EndRequest));
}
private void Application_BeginRequest(Object source, EventArgs e)
{
// Create HttpApplication and HttpContext objects to access
// request and response properties.
System.Threading.Thread oProcessingThread;
HttpApplication application = (HttpApplication)source;
ProcessRequest oRequestProcessor=new ProcessRequest();
oRequestProcessor.HttpRequest=application;
oProcessingThread =new System.Threading.Thread(new
System.Threading.ThreadStart(oRequestProcessor.ProcessingThread));
oProcessingThread.Start();
}
private void Application_EndRequest(Object source, EventArgs e)
{
// HttpApplication application = (HttpApplication)source;
// HttpContext context = application.Context;
}
public void Dispose()
{
}
}
I am trying to write a multi-threaded HTTP module that handles the
OnBeginRequest and logs it. What I am trying to do is to offload the
logging to another thread which will allow the http module to release
the OnBeginRequest.
The issue that I have is that I keep on getting "Request is not
available in this context" exceptions.
The following is the code I am using:
using System;
using System.Web;
public class ProcessRequest
{
public HttpApplication HttpRequest;
public void ProcessingThread()
{
try
{
string sRequestUrl;
if (HttpRequest.Request!=null)
{
sRequestUrl=HttpRequest.Request.HttpMethod;
System.Diagnostics.Debug.WriteLine(sRequestUrl);
}
}
catch (System.Exception ex)
{
throw ex;
}
}
}
public class HttpRequestLogger : IHttpModule
{
protected System.Collections.Queue oHttpRequestQueue= new
System.Collections.Queue();
protected bool bModuleRunning =false;
public HttpRequestLogger()
{
}
// In the Init function, register for HttpApplication
// events by adding your handlers.
public void Init(HttpApplication application)
{
application.BeginRequest +=
(new EventHandler(this.Application_BeginRequest));
application.EndRequest +=
(new EventHandler(this.Application_EndRequest));
}
private void Application_BeginRequest(Object source, EventArgs e)
{
// Create HttpApplication and HttpContext objects to access
// request and response properties.
System.Threading.Thread oProcessingThread;
HttpApplication application = (HttpApplication)source;
ProcessRequest oRequestProcessor=new ProcessRequest();
oRequestProcessor.HttpRequest=application;
oProcessingThread =new System.Threading.Thread(new
System.Threading.ThreadStart(oRequestProcessor.ProcessingThread));
oProcessingThread.Start();
}
private void Application_EndRequest(Object source, EventArgs e)
{
// HttpApplication application = (HttpApplication)source;
// HttpContext context = application.Context;
}
public void Dispose()
{
}
}