473,395 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

objects in session

I've been developing in .net for approx 6 months now and would like an
opinion on whether it is ok to use session to store objects?

I normally create a property such as below in code behind on every page
that will use the object.

Public Property Environment() As bsEnvironment
Get
Return CType(Session("Environment"), bsEnvironment)
End Get
Set(ByVal Value As bsEnvironment)
Session("Environment") = Value
End Set
End Property

To populate properties I would use:

Dim environment As New bsEnvironment()
environment.Background = "White"
environment.Foreground = "Black"
Session("environment") = environment

On my other pages I would just access the object using
Environment.Background etc..

Is this the correct way to have objects available to many pages? Back
in the asp days I remember that using session to store objects was
advised against. Are things different now with .net?

Opinions valued.

Regards

Oct 26 '06 #1
4 1265
So you are not using the Set of your property definition? You are putting it
directly into session? Why bother with the property then?

Also, it is a lot of work to rewrite these properties on every page. I would
expect these properties to be defined once in an object someplace (like
shared properties), and then you call them to get things in and out of
session.

There is nothing wrong with putting things in session. There are always
considerations, such as, making sure you deal properly with the situation
where the session has timed out, you don't put too many things in session
(as you can run out of memory if you are putting tons of large objects),
etc.But in general there is nothing wrong with using session.

<ma**************@yahoo.co.ukwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
I've been developing in .net for approx 6 months now and would like an
opinion on whether it is ok to use session to store objects?

I normally create a property such as below in code behind on every page
that will use the object.

Public Property Environment() As bsEnvironment
Get
Return CType(Session("Environment"), bsEnvironment)
End Get
Set(ByVal Value As bsEnvironment)
Session("Environment") = Value
End Set
End Property

To populate properties I would use:

Dim environment As New bsEnvironment()
environment.Background = "White"
environment.Foreground = "Black"
Session("environment") = environment

On my other pages I would just access the object using
Environment.Background etc..

Is this the correct way to have objects available to many pages? Back
in the asp days I remember that using session to store objects was
advised against. Are things different now with .net?

Opinions valued.

Regards

Oct 26 '06 #2
I will concur with Marina. In traditional ASP, session was overused and it
was not wise. Not as big a deal with ASP.NET. If the objects are large or
there are lots of them, you will most likely kill scalability compared to
grabbing data as needed, but there is nothing inherently wrong with storing
in session.

I am not sure, however, that I would store object properties in session.
Store an entire property bag object in session? Sure. But, store all
properties on an object in Session? That is blurring the lines and could be
a train wreck if you continue down that path.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
<ma**************@yahoo.co.ukwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
I've been developing in .net for approx 6 months now and would like an
opinion on whether it is ok to use session to store objects?

I normally create a property such as below in code behind on every page
that will use the object.

Public Property Environment() As bsEnvironment
Get
Return CType(Session("Environment"), bsEnvironment)
End Get
Set(ByVal Value As bsEnvironment)
Session("Environment") = Value
End Set
End Property

To populate properties I would use:

Dim environment As New bsEnvironment()
environment.Background = "White"
environment.Foreground = "Black"
Session("environment") = environment

On my other pages I would just access the object using
Environment.Background etc..

Is this the correct way to have objects available to many pages? Back
in the asp days I remember that using session to store objects was
advised against. Are things different now with .net?

Opinions valued.

Regards

Oct 26 '06 #3
Thanks for the reply.

Marina Levit [MVP] wrote:
So you are not using the Set of your property definition? You are putting it
directly into session? Why bother with the property then?
Because it was the way I was shown to do it. :(

So rather than using the property on every page I should use something
like:

Dim env As bsEnvironment = Session("Environment")

Makes sense. Therefore I can do away with the property...Is this what
you meant?

Oct 26 '06 #4
That isn't what I said at all.

I said if you are going to bother writing a property, then always go through
the property. If you are going to use Session directly, then don't bother
with the property. But there is no point in writing a property, and then not
using it.

I also suggested that you do not copy the same property into every page, but
rather, you write it once in a central place, and have everything use it.

<ma**************@yahoo.co.ukwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Thanks for the reply.

Marina Levit [MVP] wrote:
>So you are not using the Set of your property definition? You are putting
it
directly into session? Why bother with the property then?

Because it was the way I was shown to do it. :(

So rather than using the property on every page I should use something
like:

Dim env As bsEnvironment = Session("Environment")

Makes sense. Therefore I can do away with the property...Is this what
you meant?

Oct 27 '06 #5

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

Similar topics

2
by: Jim | last post by:
I have been tasked with migrating a legacy asp website into asp.net. The website uses COM objects in session all over the place (which is terrible but because the code is going to be eventually...
8
by: Dave Wurtz | last post by:
All, I'm new to ASP development and I have a basic design question: Is it ok to store business objects to session variables or is there a better way to keep object information? For example,...
8
by: Keith-Earl | last post by:
Okay, looking for a Best Practice. We are building a classic three tier app in VB.NET. When we load up a WebForm we have access to very useful objects such as the Session object. We frequently...
2
by: Chris | last post by:
Hi, I am building a single webform/webpage asp.net application using VB.NET. I have created lots of classes for this web application. On page load I use a facade controller pattern class to...
10
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...
47
by: Max | last post by:
Due to the behaviour of a particular COM object, I need to ensure that a request for a particular ASP page is finalized before another request for the page is processed. Does IIS have a way to...
2
by: HankD | last post by:
Hi, I am having a problem with instantiating two custom objects so they DO NOT point to the same memory location. What is happening is that changes I am making to my object1 are changing object2. I...
3
by: Maximiliano | last post by:
Hello, I have an asp.net project that calculates a general tax. Ok, this tax is a big object formed with another child objects (as a mather of fact 15 another child object within it), like Ship,...
13
by: DigitalDave | last post by:
A project I did awhile back stored php5 objects in elements of the $_SESSION array between pages that were navigated on the site. There were object classes representing teachers, and object classes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.