Answered by:
How to check page Visits

Question
-
User2129316869 posted
Please I need to know when a someone visits a page and when this happens insert a value in a column in a database. How can i do this please?
Wednesday, June 4, 2014 11:12 AM
Answers
-
User-821857111 posted
You can put some code in a _PageStart.cshtml file which you place in the root of your site. The code can be as simple as
var sql = "INSERT INTO PageViews (PageVisited, DateVisited) VALUES (@0, GetDate())"; db.Open("MyDb").Execute(sql, Request.Url);
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 4, 2014 12:05 PM -
User-1980594115 posted
If you are tracking guests accessing a page, you can do something like follows. This will track every individual page accessed if placed in _SiteLayout.cshtml"
@{ // IP Address var ipAddr = HttpContext.Current.Request.ServerVariables["Remote_Addr"]; // Called Web Page var toPage = Path.GetFileName(HttpContext.Current.Request.ServerVariables["URL"]); // Date Time Stamp var entryTimeStamp = DateTime.Now; } @{ // Record Web Page Access Log var insertSubQuery = "INSERT INTO entryExitLog (ipAddr, entryPage, entryTimeStamp " + "VALUES (@0, @1, @2)"; db.Execute(insertSubQuery, ipAddr, toPage, entryTimeStamp); }
If you are tracking only one page, then the toPage variable would be your page name. If you know the users (logged in) accessing the page, then you can include their log in information.
Another option to check into is using Google Analytics.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 4, 2014 12:15 PM -
User1372787940 posted
Use google anayltics ... you can see everything..what pages people view, how many times they view them, how many views on each page..It is very simple you just copy and past the code they give you its quick and easy
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 4, 2014 12:25 PM -
All replies
-
User-821857111 posted
You can put some code in a _PageStart.cshtml file which you place in the root of your site. The code can be as simple as
var sql = "INSERT INTO PageViews (PageVisited, DateVisited) VALUES (@0, GetDate())"; db.Open("MyDb").Execute(sql, Request.Url);
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 4, 2014 12:05 PM -
User-1980594115 posted
If you are tracking guests accessing a page, you can do something like follows. This will track every individual page accessed if placed in _SiteLayout.cshtml"
@{ // IP Address var ipAddr = HttpContext.Current.Request.ServerVariables["Remote_Addr"]; // Called Web Page var toPage = Path.GetFileName(HttpContext.Current.Request.ServerVariables["URL"]); // Date Time Stamp var entryTimeStamp = DateTime.Now; } @{ // Record Web Page Access Log var insertSubQuery = "INSERT INTO entryExitLog (ipAddr, entryPage, entryTimeStamp " + "VALUES (@0, @1, @2)"; db.Execute(insertSubQuery, ipAddr, toPage, entryTimeStamp); }
If you are tracking only one page, then the toPage variable would be your page name. If you know the users (logged in) accessing the page, then you can include their log in information.
Another option to check into is using Google Analytics.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 4, 2014 12:15 PM -
User1372787940 posted
Use google anayltics ... you can see everything..what pages people view, how many times they view them, how many views on each page..It is very simple you just copy and past the code they give you its quick and easy
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 4, 2014 12:25 PM -
-
User2129316869 posted
Thanks for all the contribution. They all helped.
Best Regards
Thursday, June 5, 2014 4:14 AM