Asp.net mvc - static constructor

I want to ask a question about asp.net mvc

  • Does the static constructor initiate every user request?
  • Is a static share available for each user?
+1


source to share


2 answers


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



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

  • Yes, static data travels across the entire application domain. Each application domain will have different static data. Therefore, unless you are using a web garden or web farm script, it is used for all users. Note: if you declare your static fields as ThreadStatic

    , they will only be available to one thread, which probably doesn't make much sense in an ASP.NET application.

+5


source


If I understand your question correctly:

  • Yes, you have global.aspx that contain event handlers for what you are looking for.
  • The Application Cache will give you what you are looking for. Application.Cache or something that I cannot print from memory ...


Cheers and Merry Christmas (if applicable)

0


source







All Articles