Last post Mar 28, 2007 02:56 AM by Raymond Wen - MSFT
Mar 26, 2007 10:11 PM|Pierre|LINK
We're using asp.net 2.0 on our server and per our agreement with our data-center we only pay for inbound traffic.
What we want to do is monitor inbound requests on all our web-applications on the server, to log the size of each request so we can see where we're wasting bandwidth. I'm not sure what the easiest way is to do this. Can IIS maybe give me that information
already? Do I need to change every application to do this? Or can I write a handler to do this transparently without affecting my applications?
Any suggestions appreciated.
Mar 27, 2007 04:33 AM|Raymond Wen - MSFT|LINK
Instead of using httpHandler, you should use a httpModule.
public class LogModule : IHttpModule
public void Init(HttpApplication context)
context.BeginRequest += new EventHandler(context_BeginRequest);
void context_BeginRequest(object sender, EventArgs e)
HttpApplication app = sender as HttpApplication;
HttpContext context = app.Context;
HttpWorkerRequest workerRequest =
((IServiceProvider)context).GetService(typeof(HttpWorkerRequest)) as HttpWorkerRequest;
int length = int.Parse(workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
// log it some where
Hope it hleps.
Mar 28, 2007 02:42 AM|Pierre|LINK
Is there a way to have this work for all my applications without installing it in each one seperately? Otherwise I'd rather just build the code into my global.asax, but I want to avoid changing every app on my server to do this. It will take me days to do
Mar 28, 2007 02:56 AM|Raymond Wen - MSFT|LINK
You can compile this class into an assembly, install it into GAC.
Register it in [Windows Folder]\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config, so that it will take effect on all applications on this server.