|
At first I was shocked this worked ... but actually that points to the difference between the two events. Basically, your application is static - there's only one instance, ever - but requests are not. By default with ASP.NET you can service 20 requests at the same time ( this is set in machine.config ).
So, the application only starts once, until it closes, then it can be started again. That's the "English language" version of the Application_Start event. But, it's a server application, that fields multiple requests from clients; it gives each request its own thread to run on. ( These live in the "thread pool" meaning when one is finished, it waits for more work to do, instead of dieing, which makes your app run faster because it doesn't have to constantly "give birth" to lots of threads. ) So the "English" version of Application_BeginRequest is that this happens when the web server ( IIS ) starts working on a request from a client, and gives it its own thread to run your code on.
That's why at first I didn't think this would work; each request is likely to be serviced by a different thread, even for the same page from the same client. But that's why you had to put your code in one event, and not the other.
|