As you can see by the ASP.NET Lifecycle on MSDN, the Application_Start
event not only happens long before the AcquireRequestState
event where the request object is built, it is also done out of band with the request lifecycle altogether. In other words, Application_Start
occurs only once when the application starts or when the application pool recycles, not once per request.
So, the answer to your question is simply that you can't do that (unless of course you set a static variable in the Application_Start
event and use either Application_BeginRequest
as in Darin's answer or an MVC filter to actually do the logging).
But MVC includes authorization filters and action filters which are meant for implementing cross-cutting concerns such as logging and/or auditing of the current user's IP address. Authorization and action filters do not run until after the request object has been created.