views:

479

answers:

2

i want ask some question about asp.net mvc

  1. Is static constructor will init every user request?
  2. Is static data share for every user?
+3  A: 

This answer is completely generic and not only for ASP.NET MVC.

  1. Static constructors will run at most once per application domain. It's guaranteed that it's run before any static or instance member access for that class. So no, it won't be called for every request.

  2. Yes, static data is shared through the whole application domain. Every application domain will have distinct static data. So unless you are running on a Web garden or Web farm scenario, it's shared for all users. Side note: If you declare your static fields as ThreadStatic, they will only be available for a single thread, which probably doesn't make much sense in an ASP.NET application.

Mehrdad Afshari
A: 

Hi,

If I understand your question correctly:

  1. Yes, you have a global.aspx that contain eventhandlers for what you are looking for.
  2. Application cache would give you what you are looking for. Application.Cache or something I can't type from memory...

Cheers and merry christmas (if applicable)

elgrego