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开发者_JS百科 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.
Get request do not carry any information other than in url.
精彩评论