Ciel
Ciel

Reputation: 17752

ASP.NET MVC Session State

Is there any way to tell if a visitor to a site is new, or just the same one over and over again, for the purpose of a hit counter?

Sessions don't really seem to exist in MVC, so I know I can't really use them...

Upvotes: 0

Views: 630

Answers (2)

cllpse
cllpse

Reputation: 21727

You can use sessions in ASP.NET MVC, but as Mehrdad points out, storing this kind of information on the server is not the way to go about it--use JavaScript cookies instead. And let your clients do the "heavy lifting".

Quircksmode has a great article on using JavaScript cookies.

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421988

Is there any way to tell if a visitor to a site is new, or just the same one over and over again, for the purpose of a hit counter?

There's not a 100% reliable way due to the stateless nature of the web but for the purposes of a counter, setting a cookie and checking whether it's there or not is adequate for the most cases.

Sessions don't really seem to exist in MVC, so I know I can't really use them...

This is not true. You can use Session in ASP.NET MVC too. Although, in general, you should avoid server-side state as much as possible when you don't need it to ease scalability.

Upvotes: 4

Related Questions