A basic approach is to use the session start and end event (see
global.asax). Increase an application variable when a session starts and
decrease the application variable when the session ends.
That said the end event of a session doesn't happen in some cases (when
using the SQL Server provider) or is/was not known to be terribly reliable
so my personal approach would be :
- to keep track in an application variable of each session I heard about
including a timestamp
- counting recently used session (whatever criteria you want as you have a
timestamp) gives the number of users
- you can remove old sessions records from the list and you don't care about
session events happening or not
In all cases this is just indicative as http is stateless and you don't know
immediately when a user closes his browser. Some are doing a server side
call to close the session from a client side event but I never found it was
worth the trouble to go against http nature.
You should find lot of resources about this on Google (especially #1 and #3,
not sure about #2). In all cases, isolete this code so that you'll be able
to change the method you are suing at will without changing anyhting in the
rest of your code.
--
Patrice
"_Who" <Ca**********@r oadrunner.coma écrit dans le message de groupe de
discussion : #K************* *@TK2MSFTNGP04. phx.gbl...
The answer your last question is yes.
But I find mostly cookie code on the internet uses JavaScript and from
your reply I now know that with ASP.NET that is not the way to go. For
that I thank you.
"Patrice" <http://www.chez.com/scribe/wrote in message
news:F5******** *************** ***********@mic rosoft.com...
>IMO don't save something you find easily on the web. Knowing you can is
enough and you'll have no problem to find this again when needed...
You have likely more than this cookie to produce an approximate number of
current users on your site and no I wouldn't do this way (you have a
cookie though for your ASP.NET session).
I remember to have done this at least one time (setting the cookie client
side) but I don't remember what was the purpose.
I would do things the other way round. Instead of asking why you would do
something in a particular way, tell rather what you are trying to do and
someone will likely give - if not the mythical "best way" - at least a
possible logical way to do that...
Do you want to display on your page an approximate number of users
currently visiting the site ?
--
Patrice
"_Who" <Ca**********@r oadrunner.coma écrit dans le message de groupe de
discussion : Of************* *@TK2MSFTNGP06. phx.gbl...
>>There is much JavaScript cookie code on the Internet and in books, that
shows how to write, read, and take apart what is read.
I have some saved. I was wondering if there is any reason for me to save
that.
Also, I work alone so it would be valuable to hear that using
Request.Cooki es and Response.Cookie s is a good approach not withstanding
all the code that uses document.cookie .
It's confusing. For example your statement: "For example if you have to
set them client side... "
Is there some reason to do that?
In fact, I'm looking at a 75-line code that is used to display the
number of visits by the person to the site. It uses document.cookie and
JavaScript. Is that the way you'd do it?
Thanks for helping