i want to store data lets say ID in a centralized area that i can access it from any class, statics won't help because it will be overwritten, i need something like modules in vb (i don't know if it really helps me) how can i do this in asp/C#?
3 Answers
You could use:
- ASP.NET Cache
- Session State
- Application State
- Database
Not knowing exactly what it is you want to centralise (and the scope of it) I cannot offer advice on what option to pick. Most of the time, Session state tends to be used.
You've won the first battle by opting not to use statics, they are unpredictable on IIS due to Application Pool recycling.

- 1
- 1

- 63,413
- 11
- 150
- 187
you may store it on Session variable like;
Session["myParam"] = myobject;
you may retrieve value like;
var temp = (MyClass) Session["myParam"];

- 14,643
- 4
- 38
- 54
If you are in a web context so you can use Application object because this is a common object for all the classes and pages.
So add your value to application then read it once needed from the other location.
you can as well get the same behavior if you define a static class with static variable inside. So take a look to singletone design pattern to get more details for this solution

- 11
- 3