Is it better practice to use class variables, or the session cache in ASP.NET? I have a variable which I need to persist across page loads. Is it better to use:
public class MyClass {
private SomeObject anObject;
private method1() {
anObject = new SomeObject();
}
private method2() {
// do something with anObject
}
}
or
public class MyClass {
private method1() {
Session["anObject"] = new SomeObject();
}
private method2() {
SomeObject anObject = (SomeObject)Session["anObject"];
}
}