473,698 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to share objects in an ASP.NET application

I am currently developing a statistics system in ASP.NET, and need to share
information about the customers websites, in this application.

(I have simplified my code, to make my project easier to explain.)

The simple version of the system is like this : A customer inserts HTML code
on his webpage, which contacts my statistics server each time the customers
website recieves a hit - like a classic "register website traffic" system.

When the customers hit reaches my web application, I need to maintain info
and state about the customers website - therefore I have a "website" class,
which hold information about the customer website (raw hits, unique hits,
website name, hit today ect).

So the first time a customer hits my servers, I need to instantiate an
instance of the website class, and update the information in this class.
Next time I recieve a request for the same customer, I only need to update
the websites information in the instance of that class.

So, here is a picture of how it works today, when the first hit comes in :

1. Customer #100 sends a request to my statistics application.
2. I have no information about customer #100, so I instantiate a new
instance of the "website" class.
3. I update information, and sets the "unique hits" variable to 1 (as this
is the first hit).

After this, all hits coming after the first hit, only updates information in
the "website" class (ie. adds 1 to the "unique hits" variabel) - like in
step 3.

I think (and hope) all the above is readable and understandable.

My problem now, is how I share these website classes in the global
application ????

Today I have a shared collection, which hold each instance of the website
class - like this :

public shared websites as new sortedlist

This shared collection can be accessed from all classes in my application,
and actually this works fine.

But, when my collection of websites reaches a certain limit (about 2500
"website" classes), the application starts to become VERY slow, and after
10-15 minutes it totally slows down and becomes useless.

And listen to me - we are talking VERY SLOW here - it runs on dual xeon HP
server, so hardware is enough for testcase ...

My question is now, if I am doing this the right way ??? How are you guys
shared objects among pages in an ASP.NET application ???

Is there are correct way to share objects globally in an ASP.NET application
?
-
Regards,
Tony Fonager, Denmark
Nov 18 '05 #1
6 1615
Check out the Appplication Cache.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Tony Fonager" <tony@dontspamt hisemailadress_ fonager.dk> wrote in message
news:#r******** ******@tk2msftn gp13.phx.gbl...
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application.

(I have simplified my code, to make my project easier to explain.)

The simple version of the system is like this : A customer inserts HTML code on his webpage, which contacts my statistics server each time the customers website recieves a hit - like a classic "register website traffic" system.

When the customers hit reaches my web application, I need to maintain info
and state about the customers website - therefore I have a "website" class, which hold information about the customer website (raw hits, unique hits,
website name, hit today ect).

So the first time a customer hits my servers, I need to instantiate an
instance of the website class, and update the information in this class.
Next time I recieve a request for the same customer, I only need to update
the websites information in the instance of that class.

So, here is a picture of how it works today, when the first hit comes in :
1. Customer #100 sends a request to my statistics application.
2. I have no information about customer #100, so I instantiate a new
instance of the "website" class.
3. I update information, and sets the "unique hits" variable to 1 (as this
is the first hit).

After this, all hits coming after the first hit, only updates information in the "website" class (ie. adds 1 to the "unique hits" variabel) - like in
step 3.

I think (and hope) all the above is readable and understandable.

My problem now, is how I share these website classes in the global
application ????

Today I have a shared collection, which hold each instance of the website
class - like this :

public shared websites as new sortedlist

This shared collection can be accessed from all classes in my application,
and actually this works fine.

But, when my collection of websites reaches a certain limit (about 2500
"website" classes), the application starts to become VERY slow, and after
10-15 minutes it totally slows down and becomes useless.

And listen to me - we are talking VERY SLOW here - it runs on dual xeon HP
server, so hardware is enough for testcase ...

My question is now, if I am doing this the right way ??? How are you guys
shared objects among pages in an ASP.NET application ???

Is there are correct way to share objects globally in an ASP.NET application ?
-
Regards,
Tony Fonager, Denmark

Nov 18 '05 #2
Hello Tony!
If you make your class a Singleton and declare yout collection i
global.asax?
The Singleton design pattern lets you use tha class without instanciating it
first, it keeps a private member of it's own type and uses that instance if
it is instanciated.

to use a Singleton class in code, just use it like this:

mynamespace.myc lass.Instance.m yMethod()

Instance is a public function.

Example code:

Class myClass

Public Shared moMyClass As myClass = Nothing

Private Sub new()
'private constructor disallowing other to create object directly
End Sub

Friend Shared Function Instance() As myClass
If moMyClass = Nothing Then
'First instance
'return a new object
moMyClass = New myClass()
Return moMyClass
Else
Return moMyClass
End If
End Function

Public Function myMethod()
'do something clever
End Function
End Class

Hope it helps!
"Tony Fonager" <tony@dontspamt hisemailadress_ fonager.dk> skrev i meddelandet
news:#r******** ******@tk2msftn gp13.phx.gbl...
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application.

(I have simplified my code, to make my project easier to explain.)

The simple version of the system is like this : A customer inserts HTML code on his webpage, which contacts my statistics server each time the customers website recieves a hit - like a classic "register website traffic" system.

When the customers hit reaches my web application, I need to maintain info
and state about the customers website - therefore I have a "website" class, which hold information about the customer website (raw hits, unique hits,
website name, hit today ect).

So the first time a customer hits my servers, I need to instantiate an
instance of the website class, and update the information in this class.
Next time I recieve a request for the same customer, I only need to update
the websites information in the instance of that class.

So, here is a picture of how it works today, when the first hit comes in :
1. Customer #100 sends a request to my statistics application.
2. I have no information about customer #100, so I instantiate a new
instance of the "website" class.
3. I update information, and sets the "unique hits" variable to 1 (as this
is the first hit).

After this, all hits coming after the first hit, only updates information in the "website" class (ie. adds 1 to the "unique hits" variabel) - like in
step 3.

I think (and hope) all the above is readable and understandable.

My problem now, is how I share these website classes in the global
application ????

Today I have a shared collection, which hold each instance of the website
class - like this :

public shared websites as new sortedlist

This shared collection can be accessed from all classes in my application,
and actually this works fine.

But, when my collection of websites reaches a certain limit (about 2500
"website" classes), the application starts to become VERY slow, and after
10-15 minutes it totally slows down and becomes useless.

And listen to me - we are talking VERY SLOW here - it runs on dual xeon HP
server, so hardware is enough for testcase ...

My question is now, if I am doing this the right way ??? How are you guys
shared objects among pages in an ASP.NET application ???

Is there are correct way to share objects globally in an ASP.NET application ?
-
Regards,
Tony Fonager, Denmark

Nov 18 '05 #3
Do you want me to add the "website" class into the application cache ?

I cannot see how this can be done - I need to call functions on this
"website" object and set properties again and again - how does this work, if
the object is put into the cache ?

-
Regards,
Tony

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
Check out the Appplication Cache.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Nov 18 '05 #4
HenkeBenke,

I think I understand the concept of singletons, but anyhow I cannot see how
this makes it a better solution than the way I am doing it today !

Does singletons use less memory, are they faster or what is it (sorry, no
experience with singleton design patter).

And is there a difference when sharing the collection in globas.asax instead
of my page ?
-
Regards,
Tony Fonager

"HenkeBenke " <he************ @hotmail.com> wrote in message
news:ec******** *****@TK2MSFTNG P11.phx.gbl...
Hello Tony!
If you make your class a Singleton and declare yout collection i
global.asax?
The Singleton design pattern lets you use tha class without instanciating it first, it keeps a private member of it's own type and uses that instance if it is instanciated.

to use a Singleton class in code, just use it like this:

mynamespace.myc lass.Instance.m yMethod()

Instance is a public function.

Example code:

Class myClass

Public Shared moMyClass As myClass = Nothing

Private Sub new()
'private constructor disallowing other to create object directly
End Sub

Friend Shared Function Instance() As myClass
If moMyClass = Nothing Then
'First instance
'return a new object
moMyClass = New myClass()
Return moMyClass
Else
Return moMyClass
End If
End Function

Public Function myMethod()
'do something clever
End Function
End Class

Nov 18 '05 #5
You post made me think ...

Why would I like only one instance of my website class ? My design needs me
to have an instance for each website (customer website), so that I can
differentiate each customers web traffic, recorded by my system!

Dont you agree ?
Regards,
Tony
Nov 18 '05 #6
Hi Tony,
Do you want me to add the "website" class into the application cache ?

I cannot see how this can be done - I need to call functions on this
"website" object and set properties again and again - how does this work, if the object is put into the cache ?
Application cache is simply a memory space. When you cache an object, it is
stored in memory. You can certainly use it any time. You could store a
Collection of "website" objects in the Application cache. Example:

((ArrayList) Cache["websCollection "]).Add(new website()); // Store

website w = ((ArrayList) Cache["websCollection "])[0]; // Fetch

I would recommend using the Cache, as it is thread-safe.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Tony Fonager" <tony@dontspamt hisemailadress_ fonager.dk> wrote in message
news:un******** ******@TK2MSFTN GP14.phx.gbl... Do you want me to add the "website" class into the application cache ?

I cannot see how this can be done - I need to call functions on this
"website" object and set properties again and again - how does this work, if the object is put into the cache ?

-
Regards,
Tony

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
Check out the Appplication Cache.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living


Nov 18 '05 #7

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

Similar topics

3
1983
by: kyle.tk | last post by:
So I have a central list of python objects that I want to be able to share between different process that are possibly on different computers on the network. Some of the processes will add objects to list and another process will be a GUI that will view objects in the list. I want this all to happen in real-time (e.g once a processes adds an object to the list the GUI will see it.) What would be the best way to accomplish this. Some of...
346
16516
by: rkusenet | last post by:
http://biz.yahoo.com/rc/040526/tech_database_marketshare_1.html Interesting to see that database sales for windows is more than Unix.
4
1810
by: Ashura | last post by:
H I want to make a project where one or more object could be shared between 2 applications For example : the first application create a connection to a web-service, this connection is stored in an object (through a service perhaps). A second application is launch and I want this application, use the same connection as the frst one (so retrieve the object where the connection is stored) Any idee of th process ?? I think I need to...
1
3392
by: Macca | last post by:
Hi, I have a C# Solution/Application that contain 4 projects. Each of these projects needs at some time to access the same database. I would like to know how to share a single connection between these projects as i assume this would be more efficient than having a separate connection string for each project.
8
4548
by: Tony Fonager | last post by:
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application. (I have simplified my code, to make my project easier to explain.) The simple version of the system is like this : A customer inserts HTML code on his webpage, which contacts my statistics server each time the customers website recieves a hit - like a classic "register website traffic" system. ...
5
2171
by: Joe | last post by:
I have an application which runs in a non-secure environment. I also have an application that runs in a secure environment (both on the same machine). Is there any way to share the session data for this? Most of the site allows the user to add things to a cart (non-secure), once they choose to check-out, I need this information which was stored in the session to be read by the payment page(secured). Hope this makes sense. It's probably...
6
2965
by: tendim | last post by:
G'day group. Currently our organization us using VB6 based applications, and I am trying to push forward and migrate some of the smaller things to VB.NET, eventually migrating all applications from VB6 and other legacy languages/systems (Pure VBScript, DataEase, etc.) over to .NET. Currently, *all* user data is stored on network shares. When a user logs in to a workstation, their home drive is mounted from one share, all of their...
1
799
by: Nayana Thara | last post by:
We have a web site where we have asp and asp.net. how can we share session data b/w the two environments.
6
2179
by: Immortal Nephi | last post by:
First class is the base class. It has two data: m_Base1 and m_Base2. Second class and third class are derived classes and they are derived from first class. m_Base1 and m_Base2 are inherited into two derived classes. Second class has its own m_Base1 and m_Base2 and third class does the same. I am curious. How can second class and third class share the same m_Base1 and m_Base2? You define second class first and enter data into...
0
8673
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4365
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.