S
Sylvia A.
How can I define global classes in web application ?
Classes can be set to session variables ?
Thanks
Classes can be set to session variables ?
Thanks
How can I define global classes in web application ?
Classes can be set to session variables ?
Sylvia A. said:How can I define global classes in web application ?
carion1 said:Storing ref types in Session isn't advisable but here you go.
//create it
myObject myObjectInstance = new myObject();
...do work here...
//dump it into session
Session["myObject"] = myObjectInstance;
//pull it back out of session
myObject myObjectInstance = (myObject)Session["myObject"];
I would store the information needed to re-produce the object and it's
state rather than store the object in Session.
How can I define global classes in web application ?
Classes can be set to session variables ?
Thanks
Storing objects in another object (especially in the session object) is *always* a Bad Idea.
carion1 said:Storing ref types in Session isn't advisable but here you go.
//create it
myObject myObjectInstance = new myObject();
...do work here...
//dump it into session
Session["myObject"] = myObjectInstance;
//pull it back out of session
myObject myObjectInstance = (myObject)Session["myObject"];
I would store the information needed to re-produce the object and it's
state rather than store the object in Session.
How can I define global classes in web application ?
Classes can be set to session variables ?
Thanks
As objects is the only thing that you *can* store in the Session object,
it would mean that storing anything there would always be a bad idea
Göran Andersson said:I am a little curious about your statement. Why do you say so?
As objects is the only thing that you *can* store in the Session object, it would mean that
storing anything there would always be a bad idea.
Storing objects in another object (especially in the session object) is *always* a Bad Idea.
carion1 said:Storing ref types in Session isn't advisable but here you go.
//create it
myObject myObjectInstance = new myObject();
...do work here...
//dump it into session
Session["myObject"] = myObjectInstance;
//pull it back out of session
myObject myObjectInstance = (myObject)Session["myObject"];
I would store the information needed to re-produce the object and it's
state rather than store the object in Session.
How can I define global classes in web application ?
Classes can be set to session variables ?
Thanks
For an object like a datatables, they're already marked as serializable.
For custom objects, you'd have to make sure they're serializable.
Using the Cache to store data is much more efficient than storing objects
in the Session object.
Mark Rae said:Yes, I would agree with that.
For objects which are unique per Session, especially if they are highly *unlikely* to change for
the duration of the Session (e.g. a user profile etc) I use the Cache. I tend to use the Session
object only for tiny snippets of data which have a very short lifespan e.g. maybe for persisting
data between pages where I don't want to use a QueryString etc...
Since we're on the subject, I'm interested to know your opinion on using the Application object
for persisting data which is always the same for every user and which *almost* never changes,
maybe for years and years... I'm thinking specifically of country and currency (not exchange rate)
data in a very heavily used international order processing system. Rather than fetching this data
maybe thousands of times a minute every time a user gets to the checkout page, would you consider
it sensible to store it as DataSets in the Application object e.g.
cmbCountries.DataSource = (DataSet)Application["Countries"];
re:
!> your opinion on using the Application object for persisting data which
is always
!> the same for every user and which *almost* never changes, maybe for
years and years.
The Application object is a good place to store data of that type.
The economies of scale inherent in using the Application object, as
opposed to
using the Session object, are considerable when dealing with
seldom-varying data.
Understood.
The only caveat is whether the method employed to update the data,
when an update *is* made, can be automated.
A good way to insure that would be to use a Cache and/or SqlCache
dependency.
You can cache application data based on database dependencies.
Our good friend, Peter Bromberg, explains how to do this in this article :
http://www.eggheadcafe.com/articles/20060407.asp
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.