Hello I am creating a basic counter that adds +1 everytime someone accesses the website. The problem is it adds 1 everytime someone goes to another page on the site, not when the person goes to the site for the first time, making the data very inaccurate (ex. One user that accesses the site may go to 8 different pages, therefore adding 8 to the counter, insead of 1). Is there a way to detect when a user is accessing the site on the first initial load?
I’m using asp.net 3.5 in C#.
Try using the Session_Start event in Global.asax.cs
This will add one to the counter for each user, the first time they hit a page on your site. Then, once the browser session has timed out (by default 20 minutes of inactivity on your site), another increment will occur the next time the hit your site. The timeout period is configurable.
If you want to do it for the first time they EVER hit your site, then the cookie approach mentioned by some other posters will do this. But remember, you have no way of knowing whether it is the same user, just the same computer – think Internet cafe.
Edit: Following your comment about anonymous users:
What are your authorizatioin settings? e.g.