C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to count number of visitors for website


Posted Date: 29 Jul 2008      Total Responses: 5

Posted By: suresh       Member Level: Silver     Points: 1



How to count number of visitors for website tell me brifly okay





Responses

Author: Manish Garg    29 Jul 2008Member Level: BronzeRating:     Points: 1

you can use hiddenfield control for this purpose..


Author: Sabu C Alex    29 Jul 2008Member Level: GoldRating:     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 2008Member Level: GoldRating:     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 2008Member Level: GoldRating:     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 2008Member Level: SilverRating:     Points: 1

The perfect answer is handling in global.asax file,
see the code in above (Mr.Senthil V posted)



Post Reply
You must Sign In to post a response.
Next : Vertical Scroll Bar in GridView excluding the first row (field names)
Previous : Grid view row command
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use