473,407 Members | 2,598 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,407 software developers and data experts.

Fundamental ASP.NET question

I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.

I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Thanks in advance.
Maneesh

Jul 7 '06
8 1270
On 7 Jul 2006 11:49:16 -0700, ma**********@gmail.com wrote:
I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.

I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Thanks in advance.
Maneesh
There is seldom any valid reason to use static data anyways. Why would you
even want to? Each HTTP Request is it's own universe. It may have data
saved via Session or page variables that is carried over from one request
to the next, but it must be a self contained unit in and of itself because
requests are stateless.

This means that you can't expect any data in a static variable to exist
after a round trip. It might, or it might not. It depends on whether the
web server unloads your DLL or not, and you don't really have any control
over that.

So, because the very idea of using static data is largely pointless in the
first place, I think your question about whether it's safe to do so is
irrelevent. And, that's not even getting into the issues with AppDomains
and how the framework works at a lower level.
Jul 7 '06
Erik, Thanks for your reply.
The reason is this. I usually try to have a backend class library
providing me utility functions/DAL functionality to be used by the Web
Application.
Now, I want to store the connection string in the Web.config file, and
then set some static property of the backend class (where I cannot get
a handle to the Session variable) with it, so that I can re-use it
throughout the application, whenever I want to make a connection,
instead of passing it to a backend method each time.
I'm not sure if this is a good practice, or what would be a good
practice in such a case, i.e. when you want to have a class library at
the back, but want to use some data from Web.config throughout the
lifetime of the Web Application.
Do let me know if you can shed some light on this.

regards,
Maneesh

Erik Funkenbusch wrote:
On 7 Jul 2006 11:49:16 -0700, ma**********@gmail.com wrote:
I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.

I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Thanks in advance.
Maneesh

There is seldom any valid reason to use static data anyways. Why would you
even want to? Each HTTP Request is it's own universe. It may have data
saved via Session or page variables that is carried over from one request
to the next, but it must be a self contained unit in and of itself because
requests are stateless.

This means that you can't expect any data in a static variable to exist
after a round trip. It might, or it might not. It depends on whether the
web server unloads your DLL or not, and you don't really have any control
over that.

So, because the very idea of using static data is largely pointless in the
first place, I think your question about whether it's safe to do so is
irrelevent. And, that's not even getting into the issues with AppDomains
and how the framework works at a lower level.
Jul 7 '06
re:
I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory.
Incorrect.

For *all* pages served, within an application,
there's 1 HttpApplication object which serves as their "home".

re:
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
One assembly...unless you're not caching or unless the Cache dies before the next request.
In any case, if the Cache dies...you'll *still* have only one assembly, which will be recreated.

You can fine-tune this by smart use of the Cache feature.

re:
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.
Static data is global to the application.

You cannot change static properties unless the application is restarted.
That's why they are called *static*.

Kevin Spencer explained this quite well some time ago :

Anything that is static is stored in the heap, rather than the stack.

There are 2 basic memory areas in any application.
The heap is where all the code for the app is initially loaded.

The stack is where instances (copies) of variables, functions, etc. are kept when they are
instantiated.
Data in the stack is volatile; When it goes out of scope, it is removed from the stack.

When you call a function, for example, a copy (instance) of that function is placed on the stack.
When the function exits, it is pulled off the stack.

The heap, on the other hand, is not volatile.
It remains in memory for the lifetime of the application.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<ma**********@gmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
>I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.

I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Thanks in advance.
Maneesh

Jul 7 '06
Juan,

Thanks for your answer. So if static stuff is class level, if I end up
having 1 method (static) in a utility class in the backend, which is a
class library, I'm pretty sure I will end up having synchronization
issues when multiple requests from the GUI pages cause the call to this
static method in the class library.

Am I correct, because if that is so, I will have to place appropriate
locking in the critical sections of the code.

Maneesh

Juan T. Llibre wrote:
re:
I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory.

Incorrect.

For *all* pages served, within an application,
there's 1 HttpApplication object which serves as their "home".

re:
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.

One assembly...unless you're not caching or unless the Cache dies before the next request.
In any case, if the Cache dies...you'll *still* have only one assembly, which will be recreated.

You can fine-tune this by smart use of the Cache feature.

re:
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Static data is global to the application.

You cannot change static properties unless the application is restarted.
That's why they are called *static*.

Kevin Spencer explained this quite well some time ago :

Anything that is static is stored in the heap, rather than the stack.

There are 2 basic memory areas in any application.
The heap is where all the code for the app is initially loaded.

The stack is where instances (copies) of variables, functions, etc. are kept when they are
instantiated.
Data in the stack is volatile; When it goes out of scope, it is removed from the stack.

When you call a function, for example, a copy (instance) of that functionis placed on the stack.
When the function exits, it is pulled off the stack.

The heap, on the other hand, is not volatile.
It remains in memory for the lifetime of the application.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<ma**********@gmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.

I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Thanks in advance.
Maneesh
Jul 7 '06
That depends on the type of method.

Scott Allen has explained this well :

If each thread operates on data specific to the thread, then no locks are needed.

For example:

public static string GetCookieName(Cookie c)
{
return c.Name;
}

...no problem.

If, on the other hand, multiple threads can access a shared object,
you need to be very careful:

static ArrayList cookieList = new ArrayList();

public static void AddToCookieList(Cookie c)
{
cookieList.Add(c);
}

No matter how fast the above method looks, the chance of corruption exists
because it doesn't prevent multiple threads from getting inside the Add method.

---000---

So, the issue is whether multiple threads can access the same shared object/data.

If the static method accesses and modifies data, that data would
have to be locked for the duration of the modification procedure.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Maneesh" <ma**********@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Juan,

Thanks for your answer. So if static stuff is class level, if I end up
having 1 method (static) in a utility class in the backend, which is a
class library, I'm pretty sure I will end up having synchronization
issues when multiple requests from the GUI pages cause the call to this
static method in the class library.

Am I correct, because if that is so, I will have to place appropriate
locking in the critical sections of the code.

Maneesh

Juan T. Llibre wrote:
re:
I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory.

Incorrect.

For *all* pages served, within an application,
there's 1 HttpApplication object which serves as their "home".

re:
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.

One assembly...unless you're not caching or unless the Cache dies before the next request.
In any case, if the Cache dies...you'll *still* have only one assembly, which will be recreated.

You can fine-tune this by smart use of the Cache feature.

re:
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Static data is global to the application.

You cannot change static properties unless the application is restarted.
That's why they are called *static*.

Kevin Spencer explained this quite well some time ago :

Anything that is static is stored in the heap, rather than the stack.

There are 2 basic memory areas in any application.
The heap is where all the code for the app is initially loaded.

The stack is where instances (copies) of variables, functions, etc. are kept when they are
instantiated.
Data in the stack is volatile; When it goes out of scope, it is removed from the stack.

When you call a function, for example, a copy (instance) of that function is placed on the stack.
When the function exits, it is pulled off the stack.

The heap, on the other hand, is not volatile.
It remains in memory for the lifetime of the application.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<ma**********@gmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.

I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Thanks in advance.
Maneesh

Jul 7 '06
Your "Backend method" can access the appSettings or ConnectionStrings
sections of the web.config just as the page class can. Provided it has a
reference to System.Web, its running in the same AppDomain.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Maneesh" wrote:
Erik, Thanks for your reply.
The reason is this. I usually try to have a backend class library
providing me utility functions/DAL functionality to be used by the Web
Application.
Now, I want to store the connection string in the Web.config file, and
then set some static property of the backend class (where I cannot get
a handle to the Session variable) with it, so that I can re-use it
throughout the application, whenever I want to make a connection,
instead of passing it to a backend method each time.
I'm not sure if this is a good practice, or what would be a good
practice in such a case, i.e. when you want to have a class library at
the back, but want to use some data from Web.config throughout the
lifetime of the Web Application.
Do let me know if you can shed some light on this.

regards,
Maneesh

Erik Funkenbusch wrote:
On 7 Jul 2006 11:49:16 -0700, ma**********@gmail.com wrote:
I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.
>
I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.
>
Thanks in advance.
Maneesh
There is seldom any valid reason to use static data anyways. Why would you
even want to? Each HTTP Request is it's own universe. It may have data
saved via Session or page variables that is carried over from one request
to the next, but it must be a self contained unit in and of itself because
requests are stateless.

This means that you can't expect any data in a static variable to exist
after a round trip. It might, or it might not. It depends on whether the
web server unloads your DLL or not, and you don't really have any control
over that.

So, because the very idea of using static data is largely pointless in the
first place, I think your question about whether it's safe to do so is
irrelevent. And, that's not even getting into the issues with AppDomains
and how the framework works at a lower level.

Jul 8 '06
Maneesh,
your page implements IhttpHandler. This is the interface that needs to
be implemented by any handler of a incoming request and Page is one of
them.
IHttpHandler comes with IsReuseable property which is set to false in
Page class. This method tells application factory to whether it should
be using the existing IHttpHandler object or creating a new one. So in
the case of Page, a new page object will be created every time for a
incoming request so i don't think you should have any issues with
sharing static variables.
but this would be very easy to test and remove all doubt :)

ma**********@gmail.com wrote:
I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.

I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Thanks in advance.
Maneesh
Jul 10 '06
Thanks Sonic.

I'll spike it and see what happens.

sonic wrote:
Maneesh,
your page implements IhttpHandler. This is the interface that needs to
be implemented by any handler of a incoming request and Page is one of
them.
IHttpHandler comes with IsReuseable property which is set to false in
Page class. This method tells application factory to whether it should
be using the existing IHttpHandler object or creating a new one. So in
the case of Page, a new page object will be created every time for a
incoming request so i don't think you should have any issues with
sharing static variables.
but this would be very easy to test and remove all doubt :)

ma**********@gmail.com wrote:
I have a doubt regarding the architecture, and working of the ASP.NET
framework. I haven't been able to satisfy myself with any answer.

I do understand that for each request for a resource (let's talk page),
we have 1 HttpApplication object from a pool that is managed by
HttpApplicationFactory. My question is this. After all the objects
that are created to service 1 request, is the same dll referenced for 1
page.
Let's say 3 people are trying to access Page1.aspx. Each of their
requests will be handled by 3 separate HttpApplication objects, but
will all their requests be delegated to 1 dll corresponding to
Page1.aspx, or 3 separate dlls.
The reason I'm asking is because if there is only 1 dll being used, I
will think twice before using any static properties/fields, to avoid
synchronization issues, when the properties are read/write.

Thanks in advance.
Maneesh
Jul 10 '06

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

Similar topics

51
by: Casper Bang | last post by:
My question is fundamental I beleive but it has been teasing me for a while: I have two classes in my app. The first class is instantiated as a member of my second class. Within this first class,...
3
by: Kyle Kolander | last post by:
I recently looked over the faq item relating to fundamental type sizes: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5 and was a bit surprised, as I had been taught more-or-less the...
8
by: Kyle Kolander | last post by:
Sorry, I sent this to comp.std.c++ and meant to send it here as well... Why are the minimum size guarantees for fundamental types intentionally omitted from section 3.9.1 Fundamental types of...
26
by: myName | last post by:
a && b || c is evaluated as (a && b) || c or it is evaluated as a && (b || c)
4
by: kaborka | last post by:
I have a WinForm with controls bound to a typed recordset that was generated by the Dataset Designer. There are several ComboBox controls with their DataSource bound to different lookup tables. ...
0
by: Gene Hubert | last post by:
Well, it seems fundamental to me anyway. Hopefully it is simple enough. The question is for when the source for the dragdrop is a different application that the target for the dragdrop. How...
20
by: David | last post by:
I feel like an idiot asking this but here goes: I understand the 'concept' of scope and passing data by value and/or by reference but I am confused on some specifics. class example{ int i; //my...
1
by: bharathreddy | last post by:
This Article gives an introduction to VSTS Team Foundation & fundamental difference between Visual Source Safe (VSS) and VSTS Team Foundation. Team Foundation is a set of tools and technologies...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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...

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.