Tracking Visitors in asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vyasrohit1983
    New Member
    • May 2008
    • 4

    #1

    Tracking Visitors in asp.net

    Hello all,
    I am working on asp.net 2.0 , i want to track the visitor , actually i want to log the visitor information in a text file. I want the amount of time for which user is stay on a particular page. All my pages are static meanse there is no sign in and sign out concept , user can view page directly i just want to log for how much time a user is stay on that page.

    Please give me some idea .
    Thakns
    Rohit vyas
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Each time a user browses your site they will be given a unique session ID which you can use to identify them.

    You can use the Session_OnStart event in the global.asax to record the time a session begins and the Session_OnEnd event to record the time that it finishes.

    Hope this helps,

    Dr B

    Comment

    • vyasrohit1983
      New Member
      • May 2008
      • 4

      #3
      Hi
      Thanks for the quick Reply but Session_OnStart & Session_OnEnd events not get fired when i run my application even i tried with Session_Start & Session_End events these events are also not fired.

      Originally posted by DrBunchman
      Each time a user browses your site they will be given a unique session ID which you can use to identify them.

      You can use the Session_OnStart event in the global.asax to record the time a session begins and the Session_OnEnd event to record the time that it finishes.

      Hope this helps,

      Dr B

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        They should be firing, what have you done to test them?

        Comment

        • Andrewtris
          New Member
          • May 2008
          • 1

          #5
          Then inside session_start and session_end, what i must write inside to tracking visitor and get a session who see my website?
          tx

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            Originally posted by Andrewtris
            Then inside session_start and session_end, what i must write inside to tracking visitor and get a session who see my website?
            tx
            Well, it depends on how you want to track them. I would insert a record into a database, containing the time and the user's ip address. But from what I've seen, the session_end event is unreliable, because it won't get called when someone just navigates away.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by vyasrohit1983
              Hi
              Thanks for the quick Reply but Session_OnStart & Session_OnEnd events not get fired when i run my application even i tried with Session_Start & Session_End events these events are also not fired.
              What has been suggested here to store a Session variable with the time that the user arrived at every time the user first visits your page.

              Now the thing about this is that you never know on your sever when the user leaves the page. Sessions time out after 20 minutes (by default), so your Session_End event will be fired after 20 minutes (because it will time out)....but your user may have left the page well before this 20 minute time out happens.

              Therefore, you'll have to write a bit of JavaScript that posts back to your server when the user leaves the page.

              The JavaScript event:

              window.beforeun load() = functionThatCal lsMyASPXPage()

              Fries every time your page begins to unload (don't use onunload because by that time you cannot send any more requests to the server). It is in here that you can make a quick Ajax call to your ASPX page to indicate that the user is leaving the page.

              Please note that this fires Every Time The Page Unloads. This means that when the user performs a full page postback to your aspx page this event will fire. You will need to write a bit of JavaScript code and apply it every control that performs full page postbacks. This bit of JavaScript will set a boolean that indicates to the function assigned window.beforeun load() event not call the aspx to tell it that the user has left the page.


              I probably wouldn't use Session for this problem. I would use cookies instead.

              Hope this gets you pointed in the right direction.

              -Frinny

              Comment

              Working...