c# - Writing to database on session_End event -


i'm writing httpmodule track page views user based on current session.

i have module working fine except when user abandons session. example scenario:

  • session timeout 20 minutes
  • user browses site 15 minutes
  • user navigates away site
  • session end event not triggered user have left site

i want hook session end event can bulk update page views user rather doing each time hit page (not performance wise).

is there way of detecting when happens , triggering event/piece of code log views?

sample code incase needed:

public void init(httpapplication application) {     application.postrequesthandlerexecute += application_postrequesthandlerexecute;     sessionstatemodule session = (sessionstatemodule)application.modules["session"];     session.start += session_start;     session.end += session_end; }  void session_end(object sender, eventargs e) {     visitor visitor = httpcontext.current.session["visitor"] visitor;      if (visitor != null)     {         foreach (pageitem page in visitor.pages)         {             page.updatepageviews();         }     } } 

i know isn't in line solution stands, perhaps @ solution tracking usage, such google analytics - since have put lot of effort platform.

you can integrate solution google analytics pull summary information yours required. means don't need store tracking information locally, rather make requests via api required.

i found api difficult integrate have working in solution now.

if have tracking locally, why not asynchronously you're not tying ui thread - way performance impact should minimal?


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -