473,395 Members | 1,462 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.

classes under asp.net

hi guys,

because asp.net class has a livetime of a active webpage (soon the user
changed the page, all the values saved in the class is lost)...

how do you manage to pass this?
my idea was in global.asax create an application session like

dim myClassVar as myClass
Application.unlock()
Applicaion("myClass") = myClassVar
Application.lock()
and then in all the pages do

dim myClassVar as new myClass

inside Page_load
myClassVar = Application("myClass")
....

any other ideias..., cause like this I can't call the apllication variable
inside a new class!
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)


Jun 13 '06 #1
8 1019
Hello,

Yes, if you need to access the same object for all users then store it
in Application("myClass").

If you need to access the same object for a single user then store it in
Session("myClass").

mnichols

Bruno Alexandre wrote:
hi guys,

because asp.net class has a livetime of a active webpage (soon the user
changed the page, all the values saved in the class is lost)...

how do you manage to pass this?
my idea was in global.asax create an application session like

dim myClassVar as myClass
Application.unlock()
Applicaion("myClass") = myClassVar
Application.lock()
and then in all the pages do

dim myClassVar as new myClass

inside Page_load
myClassVar = Application("myClass")
...

any other ideias..., cause like this I can't call the apllication variable
inside a new class!

Jun 13 '06 #2
but I have another class, that get's a value from this one.
How can I get the class inside a 2nd class?
I have Portal Class that has all values/functions and subs to manipulate a
user
I have Stocks Class that has the same but only for Stocks proposals
I have Warranty Class that has the same for Product warranty information

inside Stocks Class I call the Portal.idDistributor (the Distributor ID) so
I can retrieve only his stock, but I get an error everytime I do the
Dim myPortal as new Portal
myPortal = session("myPortalClass")
inside the STocks Class, it underlines the session saying that is not
defined...

then I change it to:
Dim mySession As HttpApplicationState = Nothing
Dim myPortal As Portal = mySession("myPortalClass")

but I do not have the same objects in that!

how can I acess it?

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"mnichols" <mn****************@yahoo.ca> escreveu na mensagem
news:Oz**************@TK2MSFTNGP02.phx.gbl...
Hello,

Yes, if you need to access the same object for all users then store it in
Application("myClass").

If you need to access the same object for a single user then store it in
Session("myClass").

mnichols

Bruno Alexandre wrote:
hi guys,

because asp.net class has a livetime of a active webpage (soon the user
changed the page, all the values saved in the class is lost)...

how do you manage to pass this?
my idea was in global.asax create an application session like

dim myClassVar as myClass
Application.unlock()
Applicaion("myClass") = myClassVar
Application.lock()
and then in all the pages do

dim myClassVar as new myClass

inside Page_load
myClassVar = Application("myClass")
...

any other ideias..., cause like this I can't call the apllication
variable inside a new class!

Jun 13 '06 #3
I am not a VB person, but I think the basic problem is that your class
does not know about the page or web-site. So try these:

HttpContext.Application("")
HttpContext.Session("")

They should return the current Application and Session objects.

mnichols

Bruno Alexandre wrote:
but I have another class, that get's a value from this one.
How can I get the class inside a 2nd class?
I have Portal Class that has all values/functions and subs to manipulate a
user
I have Stocks Class that has the same but only for Stocks proposals
I have Warranty Class that has the same for Product warranty information

inside Stocks Class I call the Portal.idDistributor (the Distributor ID) so
I can retrieve only his stock, but I get an error everytime I do the
Dim myPortal as new Portal
myPortal = session("myPortalClass")
inside the STocks Class, it underlines the session saying that is not
defined...

then I change it to:
Dim mySession As HttpApplicationState = Nothing
Dim myPortal As Portal = mySession("myPortalClass")

but I do not have the same objects in that!

how can I acess it?

Jun 13 '06 #4
still, you right.

just a little add, the correct code is:

HttpContext.Current.Session("myPortalClass")
thank you.

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"mnichols" <mn****************@yahoo.ca> escreveu na mensagem
news:OD**************@TK2MSFTNGP03.phx.gbl...
I am not a VB person, but I think the basic problem is that your class does
not know about the page or web-site. So try these:

HttpContext.Application("")
HttpContext.Session("")

They should return the current Application and Session objects.

mnichols

Bruno Alexandre wrote:
but I have another class, that get's a value from this one.
How can I get the class inside a 2nd class?
I have Portal Class that has all values/functions and subs to manipulate
a user
I have Stocks Class that has the same but only for Stocks proposals
I have Warranty Class that has the same for Product warranty information

inside Stocks Class I call the Portal.idDistributor (the Distributor ID)
so I can retrieve only his stock, but I get an error everytime I do the
Dim myPortal as new Portal
myPortal = session("myPortalClass")
inside the STocks Class, it underlines the session saying that is not
defined...

then I change it to:
Dim mySession As HttpApplicationState = Nothing
Dim myPortal As Portal = mySession("myPortalClass")

but I do not have the same objects in that!

how can I acess it?

Jun 13 '06 #5
The other posters have correctly shown you how to store items in the
session or application stores. However, I must caution you that placing
a lot of objects into the session can hurt performance and scalability
quite a bit. Make sure you do not keep open expensive resources (such
as database connections) in your session variables.

Unless your object has an expensive buildup/teardown process, it is
probably better to re-instantiate the object during every page view.

I cannot stree snough the importance that you not store a database or
other "heavy" connection in your session. Make sure you follow the
principle of "aquire late, release early" in web design.

In addition to the scalability issues that session variables bring, you
also have to dael with concurernce. If the same user has multiple
browsers open, you may have one sessino shared between both browsers,
but each of the browsers wants a different instance of your object
(because they are looking at different information for example)
Bruno Alexandre wrote:
hi guys,

because asp.net class has a livetime of a active webpage (soon the user
changed the page, all the values saved in the class is lost)...

how do you manage to pass this?
my idea was in global.asax create an application session like

dim myClassVar as myClass
Application.unlock()
Applicaion("myClass") = myClassVar
Application.lock()
and then in all the pages do

dim myClassVar as new myClass

inside Page_load
myClassVar = Application("myClass")
...

any other ideias..., cause like this I can't call the apllication variable
inside a new class!
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)


Jun 13 '06 #6
I only have values and functions, the functions open and close database
connections, and the values are for user profile, such as username, accesses
(boolean), birthdate, name, office name, etc...

so what you are saying is that a Session is diferent for the
browser/client/user but only if they not in the same network?
imagine there are 3 computers in a company and all of them are using the
same version of the same browser and they are all in the web application...

how can I store such information to have it diferent for all of them?

I have the same application running in classic ASP (asp 3.0) and I never had
problems like that, of course in asp 3.0 I never used classes, only here in
asp.net 2.0.

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"Jason Coyne" <ga******@gmail.com> escreveu na mensagem
news:11**********************@i40g2000cwc.googlegr oups.com...
The other posters have correctly shown you how to store items in the
session or application stores. However, I must caution you that placing
a lot of objects into the session can hurt performance and scalability
quite a bit. Make sure you do not keep open expensive resources (such
as database connections) in your session variables.

Unless your object has an expensive buildup/teardown process, it is
probably better to re-instantiate the object during every page view.

I cannot stree snough the importance that you not store a database or
other "heavy" connection in your session. Make sure you follow the
principle of "aquire late, release early" in web design.

In addition to the scalability issues that session variables bring, you
also have to dael with concurernce. If the same user has multiple
browsers open, you may have one sessino shared between both browsers,
but each of the browsers wants a different instance of your object
(because they are looking at different information for example)
Bruno Alexandre wrote:
hi guys,

because asp.net class has a livetime of a active webpage (soon the user
changed the page, all the values saved in the class is lost)...

how do you manage to pass this?
my idea was in global.asax create an application session like

dim myClassVar as myClass
Application.unlock()
Applicaion("myClass") = myClassVar
Application.lock()
and then in all the pages do

dim myClassVar as new myClass

inside Page_load
myClassVar = Application("myClass")
...

any other ideias..., cause like this I can't call the apllication variable
inside a new class!
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)

Jun 13 '06 #7
I was look depper into my application and for the entire application I
really only need 4 variables

idUser + idDIstributor + nameUser + nameDistributor

and all the access that that user have, but I can have it in one session
variable like a string and separate the values with a coma, than I can
retrive then using the split function...

I guess I will use this tactic instead saving the hole class inside the
sessions... for future sake of the application performance.

thank you 4 the thought.

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"Jason Coyne" <ga******@gmail.com> escreveu na mensagem
news:11**********************@i40g2000cwc.googlegr oups.com...
The other posters have correctly shown you how to store items in the
session or application stores. However, I must caution you that placing
a lot of objects into the session can hurt performance and scalability
quite a bit. Make sure you do not keep open expensive resources (such
as database connections) in your session variables.

Unless your object has an expensive buildup/teardown process, it is
probably better to re-instantiate the object during every page view.

I cannot stree snough the importance that you not store a database or
other "heavy" connection in your session. Make sure you follow the
principle of "aquire late, release early" in web design.

In addition to the scalability issues that session variables bring, you
also have to dael with concurernce. If the same user has multiple
browsers open, you may have one sessino shared between both browsers,
but each of the browsers wants a different instance of your object
(because they are looking at different information for example)
Bruno Alexandre wrote:
hi guys,

because asp.net class has a livetime of a active webpage (soon the user
changed the page, all the values saved in the class is lost)...

how do you manage to pass this?
my idea was in global.asax create an application session like

dim myClassVar as myClass
Application.unlock()
Applicaion("myClass") = myClassVar
Application.lock()
and then in all the pages do

dim myClassVar as new myClass

inside Page_load
myClassVar = Application("myClass")
...

any other ideias..., cause like this I can't call the apllication variable
inside a new class!
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)

Jun 13 '06 #8
> I only have values and functions, the functions open and close database
connections, and the values are for user profile, such as username, accesses
(boolean), birthdate, name, office name, etc...

so what you are saying is that a Session is diferent for the
browser/client/user but only if they not in the same network?
imagine there are 3 computers in a company and all of them are using the same
version of the same browser and they are all in the web application...

how can I store such information to have it diferent for all of them?

I have the same application running in classic ASP (asp 3.0) and I never had
problems like that, of course in asp 3.0 I never used classes, only here in
asp.net 2.0.


Sessions work about the same in ASP3 and ASP.net. They depend on a
cookie that is remembered by a browser instance.
Users behind different computers use different browser instances.
If a single user uses ctrl-N (or File | New | Window), he will open a
second window for the same browser instance. These windows share the
same session.

Hans Kesting
Jun 13 '06 #9

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

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
9
by: Jack | last post by:
Hello I have a library of calculationally intensive classes that is used both by a GUI based authoring application and by a simpler non-interactive rendering application. Both of these...
9
by: Aguilar, James | last post by:
I know that one can define an essentially unlimited number of classes in a file. And one can declare just as many in a header file. However, the question I have is, should I? Suppose that, to...
12
by: Langy | last post by:
Hello I'm fairly new to C++ but have programmed several other languages and found most of c++ fairly easy (so far!). I've come to a tutorial on classes, could someone please tell me why you...
4
by: john townsley | last post by:
do people prefer to design classes for the particular job or for a rangle of tasks they might encounter now and in the future. i am doing some simple win32 apps and picking classes is simple, but...
2
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how...
18
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise....
6
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by...
0
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid...
2
by: Amu | last post by:
i have a dll ( template class) ready which is written in VC++6. But presently i need to inherit its classes into my new C#.net project.so if there is some better solution with u then please give me...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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...

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.