views:

47

answers:

1

Here's the big picture. We're running a server in IIS 6 that hosts several web sites and applications, and we're in the process of moving the whole thing to a different data center with a slightly different setup. We've notified our users and updated our DNS info so that theoretically everyone will be happily hitting the new server from day 1, but we know that someone will inevitably fall through the cracks.

The powers that be want a "Listener" page/handler that will receive all requests to the server and log the entire request to a text file, including (especially) POST data.

That's where I'm stuck. I don't know how to implement a single handler that will receive all requests to the server. I vaguely understand IIS 6 redirection options, but they all seem to lose the POST data on the redirect. I also know a little about IIS 6's built-in logging, but it ignores POST data as well.

Is there a simple(ish) way to route all requests to the server so that they all hit a single handler, while maintaining post data?

EDIT: This is in WebForms, if that matters, but other solutions (if small) are definitely worth considering.

+1  A: 

If all the requests are POST's to ASP.NET forms then you could plugin a HttpModule to capture and log this data.

You wouldn't have to rebuild all your applications to deploy this either. All it would take is to drop the HttpModule into each application's /bin folder and add it to the <httpModules> section of your web.config files. For example:

using System;
using System.Diagnostics;
using System.Web;

public class SimpleLogger : IHttpModule
{
  private HttpApplication _application;

  public void Dispose() { }

  public void Init(HttpApplication context)
  {
    _application = context;
    context.BeginRequest += new EventHandler(Context_BeginRequest);
  }

  void Context_BeginRequest(object sender, EventArgs e)
  {
    foreach (string key in _application.Request.Form.AllKeys)
    {
      // You can get everything on the Request object at this point
      // Output to debug but you'd write to a file or a database here.
      Debug.WriteLine(key + "=" + _application.Request.Form[key]);
    }
  }
}

In your web.config file add the logger:

<httpModules>
  <add name="MyLogger" type="SimpleLogger, SimpleLogger"/>
</httpModules>

Be careful though. If your site captures credit card details or other sensitive data. You may need to ensure this is filtered out or have it encrypted and away from personel who should have no need to see this information.

Also if you're logging to files, make sure the log files are outside any public facing web folders.

Kev
This + wildcard mappings to send everything to ASP.NET worked beautifully for me. Thank you!
Joel
@joel - excellent, glad this worked for you.
Kev