开发者

ASP.NET MVC Session State

开发者 https://www.devze.com 2022-12-17 18:03 出处:网络
Is t开发者_开发技巧here 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?

Is t开发者_开发技巧here 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...


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号