Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Static class in an asp.net application.

 
Thread Tools Search this Thread
Old 12-23-2004, 03:21 AM   #1
Default Static class in an asp.net application.


Hi,

I'm starting my first asp.net application and I decided to put the
users preferences in a static class.
I thought, the static class would be just seen by current session, but
it seems it don't work like that (!?).

If I change some preference and I open a second browser session, even
another browser (netscape, opera), it seems the preferences are shared
like a big cookie among all browsers.
Thought, it is not perfectly consisten, sometimes, they do show the
same preference and some times they don't. Opera seems to be very
stubborn to read the preference when they were set through other
browser.

Well, the question is, what is the life of an static class in an
asp.net application ? is it session wide ? or it is instantiated once
for all users connected ?



craigkenisston@hotmail.com
  Reply With Quote
Old 12-23-2004, 03:45 AM   #2
Scott M.
 
Posts: n/a
Default Re: Static class in an asp.net application.
> Well, the question is, what is the life of an static class in an
> asp.net application ?



> or it is instantiated once for all users connected ?


Yes.

For storing user preferences, you should use cookies or if your users have
to log in, you can write their preferences into a database. Then, at login,
you can restore their preferences. Cookies are the simplest solution but be
aware that some users may have cookies disabled and that cookie data isn't
secure.




Scott M.
  Reply With Quote
Old 12-23-2004, 04:08 AM   #3
John Saunders
 
Posts: n/a
Default Re: Static class in an asp.net application.
<> wrote in message
news: oups.com...
> Hi,
>
> I'm starting my first asp.net application and I decided to put the
> users preferences in a static class.
> I thought, the static class would be just seen by current session, but
> it seems it don't work like that (!?).
>
> If I change some preference and I open a second browser session, even
> another browser (netscape, opera), it seems the preferences are shared
> like a big cookie among all browsers.
> Thought, it is not perfectly consisten, sometimes, they do show the
> same preference and some times they don't. Opera seems to be very
> stubborn to read the preference when they were set through other
> browser.
>
> Well, the question is, what is the life of an static class in an
> asp.net application ? is it session wide ? or it is instantiated once
> for all users connected ?





John Saunders
  Reply With Quote
Old 12-23-2004, 04:12 AM   #4
John Saunders
 
Posts: n/a
Default Re: Static class in an asp.net application.
<> wrote in message
news: oups.com...
> Well, the question is, what is the life of an static class in an
> asp.net application ? is it session wide ? or it is instantiated once
> for all users connected ?


What's the life of a static class in any application? Why would ASP.NET be
any different.

static (or Shared) members have one existence for all instances of a class
within an AppDomain. This is the opposite of an instance member, which has
one copy for each instance of a class.

This is exactly the case in ASP.NET.

If you want something which will be per-session, then you should use Session
state. If you want something which will be global to the entire application,
use Application state. Neither one is thread-safe, so be careful.

John Saunders




John Saunders
  Reply With Quote
Old 12-23-2004, 07:08 AM   #5
craigkenisston@hotmail.com
 
Posts: n/a
Default Re: Static class in an asp.net application.
John :

Thanks for your answer. It is a bit more clear now.
Still I've not found an black&white response to following, not even in
the documentation :
what is the life of the asp.net dll ?
I don't think it is exactly like any other application :
I have a C# winform application, it has some static class. If I run my
application twice, I still having different copies of the static
classes in each of the executables.
However, here asp.net seems to share the dll data among the
connections, so, you know it is a little bit different concept,
specially when comming from win32 client applications.



craigkenisston@hotmail.com
  Reply With Quote
Old 12-23-2004, 09:00 AM   #6
Hans Kesting
 
Posts: n/a
Default Re: Static class in an asp.net application.
wrote:
> John :
>
> Thanks for your answer. It is a bit more clear now.
> Still I've not found an black&white response to following, not even in
> the documentation :
> what is the life of the asp.net dll ?
> I don't think it is exactly like any other application :
> I have a C# winform application, it has some static class. If I run my
> application twice, I still having different copies of the static
> classes in each of the executables.
> However, here asp.net seems to share the dll data among the
> connections, so, you know it is a little bit different concept,
> specially when comming from win32 client applications.


If you start your winform app twice, you have two separate applications running.

An ASP.Net application is a *single* application running on a webserver,
serving *multiple* (possibly simultaneous) requests.
The application is started with the first request. I'm not sure exactly when
it finishes, it's either "never" or "after the last session has expired"
(which is default 20 minutes after the last request has been served).
Maybe someone else has a good answer here?

Hans Kesting




Hans Kesting
  Reply With Quote
Old 12-23-2004, 12:20 PM   #7
John Saunders
 
Posts: n/a
Default Re: Static class in an asp.net application.
<> wrote in message
news: oups.com...
> John :
>
> Thanks for your answer. It is a bit more clear now.
> Still I've not found an black&white response to following, not even in
> the documentation :
> what is the life of the asp.net dll ?
> I don't think it is exactly like any other application :
> I have a C# winform application, it has some static class. If I run my
> application twice, I still having different copies of the static
> classes in each of the executables.


If you run your windows application twice, you've got two separate
AppDomains, one in each process.

There is no ASP.NET equivalent to that. When a user accesses an ASP.NET web
site, ASP.NET doesn't start up a new process to run the web application, nor
does it start a new AppDomain (assuming that one is already running).
Multiple requests are serviced within the same AppDomain, therefore,
multiple requests will see the same copy of Shared data.

> However, here asp.net seems to share the dll data among the
> connections, so, you know it is a little bit different concept,
> specially when comming from win32 client applications.


Very true.

I have wondered about the path that persons like yourself take in coming
from Win32 applications to ASP.NET. Not to sound too harsh, but how did you
NOT know that an ASP.NET application is so different from a Windows Forms
application? What documentation did you look at when getting started in
ASP.NET? Whichever documentation you used, it needs to have a big Stop sign
on the cover of it saying: READ THIS FIRST: WEB APPLICATIONS ARE DIFFERENT.

You are only the tenth person this month I've seen with this same problem,
and that's probably because I can't remember numbers 11 through 20! I'm not
picking on you, rather I'd like to find out what's causing this, perhaps in
time for Microsoft to add that Stop page before VS2005 ships.

In the meantime, here's where the Stop page should point to:

The ASP.NET Page Object Model
(http://msdn.microsoft.com/library/de...asp?frame=true)



Good Luck,

John Saunders






John Saunders
  Reply With Quote
Old 12-23-2004, 01:23 PM   #8
Hans Kesting
 
Posts: n/a
Default Re: Static class in an asp.net application.
> You are only the tenth person this month I've seen with this same
> problem, and that's probably because I can't remember numbers 11
> through 20! I'm not picking on you, rather I'd like to find out
> what's causing this, perhaps in time for Microsoft to add that Stop
> page before VS2005 ships.


It's probably because VS / .Net can handle both types of application,
so it's easy to try out the "other" one. I personally have a similar
problem in reverse: things that are easy in asp.net (screen generation mostly)
are very different in a winform application.

Hans Kesting




Hans Kesting
  Reply With Quote
Old 12-23-2004, 01:38 PM   #9
John Saunders
 
Posts: n/a
Default Re: Static class in an asp.net application.
"Hans Kesting" <> wrote in message
news:...
>> You are only the tenth person this month I've seen with this same
>> problem, and that's probably because I can't remember numbers 11
>> through 20! I'm not picking on you, rather I'd like to find out
>> what's causing this, perhaps in time for Microsoft to add that Stop
>> page before VS2005 ships.

>
> It's probably because VS / .Net can handle both types of application,
> so it's easy to try out the "other" one. I personally have a similar
> problem in reverse: things that are easy in asp.net (screen generation
> mostly)
> are very different in a winform application.


Oh, well, in this case documentation wouldn't have helped, because you
didn't read any before starting!

John Saunders




John Saunders
  Reply With Quote
Old 12-23-2004, 02:32 PM   #10
Hans Kesting
 
Posts: n/a
Default Re: Static class in an asp.net application.
John Saunders wrote:
> "Hans Kesting" <> wrote in message
> news:...
>>> You are only the tenth person this month I've seen with this same
>>> problem, and that's probably because I can't remember numbers 11
>>> through 20! I'm not picking on you, rather I'd like to find out
>>> what's causing this, perhaps in time for Microsoft to add that Stop
>>> page before VS2005 ships.

>>
>> It's probably because VS / .Net can handle both types of application,
>> so it's easy to try out the "other" one. I personally have a similar
>> problem in reverse: things that are easy in asp.net (screen
>> generation mostly)
>> are very different in a winform application.

>
> Oh, well, in this case documentation wouldn't have helped, because you
> didn't read any before starting!
>
> John Saunders


Of course! I'm a developer, so I don't read documentation





Hans Kesting
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Class Loader for Web Application using Tomcat tapas.adhikary Software 0 04-22-2008 09:53 AM
ASP.NET 2.0 application does not run in WIN2k3 johnfraj Software 0 04-19-2007 08:27 AM
ASP.NET with User Interface Process Application Block robinp Software 0 03-05-2007 10:01 AM
ASP.NET application not working yogesh.sind Hardware 0 10-03-2006 09:55 AM
Storing class with session (ASP.Net) bqmassey Software 0 09-22-2006 05:37 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46