简体   繁体   中英

Session.isnewsession

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

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM