views:

18

answers:

2

Can you give an example of what might be best suited to place in the Application_Start and Session_Start subroutines? I know when each subroutine is called. Application_Start when the first user first accesses the web application. Session_Start when a user opens a session with the application. But what code belongs in each of these subroutines. What should the code in each subroutine do?

A: 

Application_Start is often used to initialize application wide settings which need to be done once per application domain like registering object containers, reading some config initialization values, ... In Session_Start you could place some code which is tied to the specific user who started the session.

Darin Dimitrov
A: 

Just any examples? Well, in an MVC site the routes are registered in Application_Start. That's also a good place to initialize an IoC container such as StructureMap. Maybe initialize some singletons you have in your application if you want them to be readily available rather than late-bound when a user accesses them (like if they have a high initialization cost and you'd rather do one slow initial hit on the website yourself than bother a customer or two with it).

Session_Start is generally used less often, but could be a good place for per-user (or per-session, realistically) tracking of some kind.

David