views:

353

answers:

3

Hello ,

Am doing an application, where i need to display no of visitors... It should display in home page .. And my home page is default.aspx... If i set a session at default home page as visitor = 1 for session... , it gets incremented for single visitor .. when i click on html pages and redirect back to default page....

How can i set session , so that it should not change for single person when he click aspx page or html page... so the number should increase (Visitor no), when new visitor visits the page????

Can anyone helpout.. Thanks in advance

A: 

If you wish to maintain number of visit in your website, you can store increment in application object, this will persist in application level
Drawback: when your application or IIS restart your application object reset.

Best way to accomplish this, store increment in Database
you can also use third party web service http://www.statcounter.com/

http://www.bestfreehitcounters.com/

Muhammad Akhtar
Why the downvote?
Henk Holterman
Another possible drawback is how to determine when someone leaves the site - the global session end event is only called for InProc sessions - if you're using Session Servers or SqlSessions, this event doesn't fire.
Zhaph - Ben Duguid
A: 

I am not total 100% sure, but you could try to set the ASP.NET Cookie properties by yourself.

        var sessionCookie = new HttpCookie  
            ("ASP.NET_SessionId", Context.Session.SessionID);
        sessionCookie.Expires.AddDays(1);
        Context.Response.SetCookie(sessionCookie);
Robert
A: 

This is a pretty simple depending on how long you want to store this data or track new users.

To track new users you should use a cookie. If the cookie / value doesn't exists then they are a new user and you need to increment your user count. If the cookie does exist then do nothing. I would put this check where a new session starts up so you are not checking it every single time a page is loaded as you really only need to do it the first time they access your page and create a new session.

Now when it is a new user, you could store that into a database with all sorts of details, like IP, date time, cookie id etc... You could even save when a user returns to your site and increment their cookies count so you can see how often they come back to your site on a user by user basis. There is a ton of different options to what you can store and how to go about it and it all depends on what your requirements / needs are.

Kelsey