473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing Objects in Session Object

I'm new to this ASP.NET caper and have the following questions.

I have a TestObject that contains about 50 fields of data and 3 member
procedures. Below is a simplified explanation of what I do.

At the start of each session I initialise this TestObject.

On entering every page I create a local TestObject and do this:
TestObject = Session("TestOb ject")

On leaving every page I do this:
Session("TestOb ject") = TestObject

This way my TestObject is kept across all the pages until my user quits
or the session times out. My site will probably have up to 100
concurrent sessions running.

Question 1:
Is there a better way to do what I've just described?
-------------------------------------------------
Question 2:
Which is the better way? (Efficient)
[assuming Test=Session("T estObject")]

Test.Field1.val ue = "1234"
or this?
Session("TestOb ject").Field1.v alue = "1234"

Is it quicker to manipulate a local object then put it into the Session
Object when finished?
-------------------------------------------------
Question 3:
Assuming the TestObject member procedures looks something like this:

Procudure SomeProc()
me.Field1.value = "1234"
'heaps more line like above...
'heaps more line like above...
End Sub
-------------------------------------------------
Would it be better to have this?

Procudure SomeProc()
ExternalProc(Me )
End Sub

And in an another module (local on the site)

Procudure ExternalProc(By Ref Test as TestObject)
test.Field1.val ue = "1234"
'heaps more line like above...
'heaps more line like above...
End Sub

I'm assuming that when you transfer a sessionobject into you code it
also has to transfer all the code defined in the Object Member
Procedures, so it those procedures only have a call to an externaly
referneced module (passing a pointer to the ojbect) then there is
hardly any code in the object itself?

Am I right in this?

Thanks....

Nov 19 '05 #1
3 1563
#1:
There are different ways, but urs is good. I hate pining things in memory.
I'd prefer to store the data in the database and cache it, which gives you
the speed benefit of in memory (like a session) and the smaller footprint of
the database. It's hard to say though, it depends on how exactly it's
beeing used, you should profile

#2
It doesn't matter too much, but creating a local variable is probably better
(ie, your first example). Otherwise you need to do a hash lookup every
time.

#3
is where you are most-wrong. your alternative doesn't make any sense. Keep
the code in the procedure. Extra lines of code aren't stored in memory for
every instance. Just because the code of your object is big, doesn't
translate into large objects. It's all about hte data you store in them.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"MrShovel" <sh********@hot mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I'm new to this ASP.NET caper and have the following questions.

I have a TestObject that contains about 50 fields of data and 3 member
procedures. Below is a simplified explanation of what I do.

At the start of each session I initialise this TestObject.

On entering every page I create a local TestObject and do this:
TestObject = Session("TestOb ject")

On leaving every page I do this:
Session("TestOb ject") = TestObject

This way my TestObject is kept across all the pages until my user quits
or the session times out. My site will probably have up to 100
concurrent sessions running.

Question 1:
Is there a better way to do what I've just described?
-------------------------------------------------
Question 2:
Which is the better way? (Efficient)
[assuming Test=Session("T estObject")]

Test.Field1.val ue = "1234"
or this?
Session("TestOb ject").Field1.v alue = "1234"

Is it quicker to manipulate a local object then put it into the Session
Object when finished?
-------------------------------------------------
Question 3:
Assuming the TestObject member procedures looks something like this:

Procudure SomeProc()
me.Field1.value = "1234"
'heaps more line like above...
'heaps more line like above...
End Sub
-------------------------------------------------
Would it be better to have this?

Procudure SomeProc()
ExternalProc(Me )
End Sub

And in an another module (local on the site)

Procudure ExternalProc(By Ref Test as TestObject)
test.Field1.val ue = "1234"
'heaps more line like above...
'heaps more line like above...
End Sub

I'm assuming that when you transfer a sessionobject into you code it
also has to transfer all the code defined in the Object Member
Procedures, so it those procedures only have a call to an externaly
referneced module (passing a pointer to the ojbect) then there is
hardly any code in the object itself?

Am I right in this?

Thanks....

Nov 19 '05 #2
When you say
TestObject = Session("TestOb ject")

TestObject is a reference to Session("TestOb ject") any change to
TestObject will be reflected in the session variable. If there are
places where you need to make changes that don't effect the session
variable implement ICloneable interface.

If this is used on every page, you might consider making a BasePage
with a protected property to access the session variable. I prefer to
encapsulate persisted variable in a property, that way I know that
initialization will be handled regardless of what event/method I am in
on the page.

C#
protected TestObject test{
get{
TestObject o = (TestObject)Ses sion["TestObject "];
if(o == null){
//whatever I need to do to create the object for the first time
Session.Add("Te stObject", o);
}
return o;
set{
...
}
}

This could be on a base page class and all pages that inherit from it
will have access. Also, if you choose to change your persistence
medium (cache, straight from db) you only have to change it in one
place.

Nov 19 '05 #3
Thanks guys... will do further research & tests...

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2586
by: mjkahn | last post by:
I've read (and read!) that you shouldn't store objects in Session variables. I've read these reasons: - The object takes up memory that may not be freed until the session times out. Better to create the object only when you actually use it. - Causes poor performance because the thread that created the object has to service all requests...
0
1099
by: Sandra | last post by:
I am using a VB6 COM object with an asp.net project. I am storing the COM object in a session variable but am having a problem accessing the COM object from the session variable. I am getting the error: QueryInterface for interface object.class failed I am able to create new instances of the object with no problems but as soon as I cast...
2
5020
by: jakk | last post by:
Below is the exception that Iam getting. It says that the DataView that Iam storing in the session is not Serializable. BUt works fine if I store in the inproc session and fails if I switch to storing the session in Sql Server. Please let me know if Iam doing anything wrong. Unable to serialize the session state. Please note that...
2
1703
by: Curt tabor | last post by:
Hi, I have several pages in my app that all use the same oleDBConnection(s). When this connection gets created, I store it as a Session variable so that other pages can access it w/o having recreate new connections every time they load. I noticed during development that when ever the app first started, the connection would not be in...
5
2993
by: James Vickers | last post by:
All, I am a bit of noob to ASP.NET, and I am writing some OO based pages to try and emerge myself into it, however, I have come across a problem that has me completely stumped! What I want to do is to take an object that I am using on one page, and pass it to another page - this, I believe is easily achievable with a session (yes, I know...
10
2152
by: Mark Rae | last post by:
Hi, This relates to the previous thread "Disappearing Sessions", but is a bit more generic so I thought I'd start a new thread. This one relates to the storing of objects in Session once only to prevent the system having to constantly query the database for the same information. I'm currently upgrading a v1.1 app to v2 (that's all I seem...
9
7284
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would be 'better' to store an instance of this class in a session-variable, so it's available all the time and needs to be instanced only once. Is...
3
2031
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve the information it contained on another page. This was significant because I am initially loading the data from the database, then storing relevent...
4
12589
by: =?Utf-8?B?YmFzdWxhc3o=?= | last post by:
Hi; I want to store a datatable (or an arraylist) as a session variable but when I try; Session = al_RecNo; I get an error that; "Cannot implicitly convert type 'System.Collections.ArrayList' to 'string'"
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7444
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7805
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3497
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.