| Author: Manish Garg 29 Jul 2008 | Member Level: Bronze | Rating: Points: 1 |
you can use hiddenfield control for this purpose..
|
| Author: Sabu C Alex 29 Jul 2008 | Member Level: Gold | Rating: Points: 4 |
hi
u can do this in two ways
1) Keep one static variable in your web app. Increment that variable in each page load event of main page.
2) Keep a field in Database. Increment that in each time
disadvantage of the fist method is when you upload new version you loss the count. You have to take care of that.
|
| Author: Senthil V 29 Jul 2008 | Member Level: Gold | Rating: Points: 6 |
Hi,
first we need to add these lines to our global.asax file
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup Application["OnlineUsers"] = 0; }
void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started Application.Lock(); Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1; Application.UnLock(); }
void Session_End(object sender, EventArgs e) { // Code that runs when a session ends. // Note: The Session_End event is raised only when the sessionstate mode // is set to InProc in the Web.config file. If session mode is set to StateServer // or SQLServer, the event is not raised. A pplication.Lock(); Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1; Application.UnLock(); }
This will allow us that whenever some distant web visitor opens our website in his browser, and new session is created for him, our "OnlineUsers" variable in the global HttpApplicationState class instance is increased.
Also when user closes his browser or does not click on any links in our website, session expires, and our "OnlineUsers" global variable is decreased.
To know more about ApplicationState and HttpApplicationState class visit this MSDN link: msdn2.microsoft.com/en-us/library/system.web.httpapplicationstate(VS.80).aspx
|
| Author: Bindu Bujji 30 Jul 2008 | Member Level: Gold | Rating: Points: 3 |
I would instantiate an application variable in the application on start pulling the value from whereever it is saved
Increment it in session onstart
Save it back to whereever in application onend
Hope this helps.... Bindu
|
| Author: Himasagar Kutikuppala 30 Jul 2008 | Member Level: Silver | Rating: Points: 1 |
The perfect answer is handling in global.asax file, see the code in above (Mr.Senthil V posted)
|