This is a simple http module that hijacks the incoming request and logs it to a file.
Using this module prevents the application from getting the post data because the input stream can only be read once.
With .NET 4.0 the module could be much smaller, and could allow the application to read the data.
To compile this, create a new "Class Library" application called PostDataLogger.
Most of this class is pieced together from stolen code (stack overflow, etc.)
Using this module prevents the application from getting the post data because the input stream can only be read once.
With .NET 4.0 the module could be much smaller, and could allow the application to read the data.
To compile this, create a new "Class Library" application called PostDataLogger.
Most of this class is pieced together from stolen code (stack overflow, etc.)
using System; using System.IO; using System.Web; ////// Dump PostDataLogger.DLL in your bin, and put this in your web.config inside of public class SimpleLogger : IHttpModule { private HttpApplication _ctx; public void Init(HttpApplication context) { _ctx = context; context.BeginRequest += new EventHandler(Context_BeginRequest); } void Context_BeginRequest(object sender, EventArgs e) { string GUID = Guid.NewGuid().ToString(); string filename = @"d:\temp\adeberry\post_data\Request_" + GUID + ".txt"; // Write a datastamp to the top of the file. System.IO.TextWriter tw = new System.IO.StreamWriter(filename, true); tw.WriteLine("[" + DateTime.Now + "]"); tw.WriteLine(""); // Dump the headers in the file foreach (string key in _ctx.Request.Headers.AllKeys) tw.WriteLine(key + ": " + _ctx.Request.Headers[key]); tw.WriteLine(""); tw.Close(); // Write POST data in binary mode. You could keep the TextWriter open and convert // the InputStream to text, but you would need to find the Encoding in the headers FileStream fs = new FileStream(filename, FileMode.Append); BinaryWriter w = new BinaryWriter(fs); byte [] bytes = new byte[_ctx.Request.InputStream.Length]; _ctx.Request.InputStream.Read(bytes, 0, (int)_ctx.Request.InputStream.Length); w.Write(bytes); w.Flush(); w.Close(); } public void Dispose() { } }/// /// //////
Comments
Post a Comment