views:

144

answers:

3

Is there an event that I can tap into in Global.asax to execute some SQL in ADO.NET for logging every time a request is made to the application?

+1  A: 

There are better ways to do it, but call whatever you want in Begin_Request.

Specifically:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
         //Do something at the beginning of every request.
    }
Ted
A: 

I think you need to investigate HttpModules (2) (3).

annakata
I was just trying to do a this.LogRequest += new EventHandler(global_asax_LogRequest); But then I get a "This operation requires IIS integrated pipeline mode." I assume the company I'm working at now is running some ASP.NET on IIS6 and some on IIS7. Thoughts?
tyndall
Yeah - I've seen it before :) http://stackoverflow.com/questions/186548/iis6-httpmodule-this-operation-requires-iis-integrated-pipeline-mode
annakata
+2  A: 

Most of the time you would be able to get the information about the request in the IIS logs. You can use logparser which provides SQL like functionality to query what you want.

To add more information to IIS logs you can use Response.AppendToLog

To capture all request for an App, you can use Application_BeginRequest event of the Global.asax

Ramesh
How would you then ask for the fullpath of the page requested minus the server path? Then ask for the server name in a separate variable. Do I get at this through two of the ServerVariables?
tyndall
In ASP.NETRequest.Url.PathAndQuery will give full url - Domain name.Request.Url.Host - will give the hostIn IIS logscs-uri-query - Will give the URI - Servercs-host - Will give the Domain name
Ramesh