1

I am working with a .Net(VB.Net) project. I need to keep track of the pages that my users keep visiting. For example i have some users say

Userid   Username
1         Pravin
2         James
3        Daniel

I have some pages in my project say

Page1.aspx,
Page2.apsx
Page3.aspx..
like this..

I want to keep track which user accessed which page with the number of times visited each day and save it in a table of sqlserver.

Please help me out in this context..

Pravin Kumar
  • 693
  • 1
  • 9
  • 35
  • @ZafKhan: I have tried by implementing a .vb class and made it call from each page's Load event.. In the .VB class file i put up the logic for inserting the pagename,userid and accessdatetime...But that seem to be not an efficient way ..So i need some efficient ways of doing it.. – Pravin Kumar Nov 20 '13 at 03:00
  • Yes it does seem inefficient because you have not added the quantity of visits to the page so this would mean there could be several records for each day for each visitor and each page maybe you could add a field named QtyVisits to your Sql table? and perform an 'update record query' which would naturally raise an error if the record was not present, but you could trap for the error and in such case perform an 'add new record' instead?. I would hazard a guess that this may consume more time so wether its more efficient i'm not sure. – Zeddy Nov 20 '13 at 03:12
  • @ZafKhan : Yes..this will consume more time as need to change all the pages in my project which count at around 600 pages... Is there any alternates instead of writing in each page's page load .. – Pravin Kumar Nov 20 '13 at 03:17
  • surely you would only change the code in your class? not every single page? as the calling convention would be the same? – Zeddy Nov 20 '13 at 03:33
  • No.. i mean to say.. I have to add the .vb class calling in each and every page..Which is not efficient for 600-700 pages.. – Pravin Kumar Nov 20 '13 at 03:39

1 Answers1

1

I think what you are looking is Application_BeginRequest

Fired when an application request is received. It's the first event fired for a request, which is often a page request (URL) that a user enters.
Note that this event is fired for every request(Images, css, java-scritp ...)
you need to check for .aspx extenstion

Edit -1

I think finding user will be difficult on BeginRequest you can use Application_AuthenticateRequest for that purpose.

void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
    var page = (Context.Handler as System.Web.UI.Page);
}

Here is more details about that event
.NET Application_BeginRequest - How to get User reference?

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
  • I need one more suggestion from you. How to prevent page postback requests like 'Button Click' on the same page.. – Pravin Kumar Nov 20 '13 at 06:21
  • @PravinKumar you can't prevent postback from `.cs` page. You need to use `java-script` `jQuery` for that. You can ask a question On SO for that. – शेखर Nov 20 '13 at 06:25
  • I mean to ask, for postback request also that 'Application_PreRequestHandlerExecute' event raises... How to filter the postback events here in this handler.. – Pravin Kumar Nov 20 '13 at 09:15