Search code examples
asp.netlogginghttphandlerhttpmodule

Log all requests (GET, POST, etc.) for all resources (.aspx, .html, .jpg, etc.) to db/file in asp.net


Is it possible to log all requests (GET, POST, etc.) for all resources (.aspx, .html,.pdf, etc.) to db or file in ASP.NET 4 application?

For the moment we use following:

   public class RequestLogger : IHttpModule
   {
      public void Dispose()
      {

      }
      public void Init(HttpApplication context)
      {
         context.PreRequestHandlerExecute += new EventHandler(mPreRequestHandlerExecute);
      }

      void mPreRequestHandlerExecute(object sender, EventArgs e)
      {
         HttpApplication app = sender as HttpApplication;
         StreamReader reader = new StreamReader(app.Request.InputStream);
         System.Diagnostics.Debug.WriteLine(reader.ReadToEnd());
      }
   }

This logger works but only for POST method, in other cases (GET) InputStream length is 0.


Solution

  • Get request do not carry any information other than in url.