1

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?

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.