I have implemented the visitor logs (that includes storing the user login date, user logoff/timeout date, and user ID) in my next ASP.NET MVC article:
MVC Basic Site: Step 4 – jqGrid Integration in MVC 4.0 using AJAX, JSON, jQuery, LINQ, and Serialization[
^]
The steps are:
1.To desing a database table linked with
Users
data. In my solution the database table used to sores the data is:
VisitorsLogs
2.To add the logic of accessing and managing the data from the table above. In my solution the associated entity class (Entity Framework partial class) is
VisitorLog
.
3.To add the user interface of creating the data entries in your
LogOn
page and main layout (or master page) by using also JavaScript. In my solution you could see this in
LogOn
view (from
Views\Account)
and in the main layout view
_Layout.cshtml.
function onWindowClosing() {
if (window.event.clientX < 0 || window.event.clientY < 0) {
$.ajax({
type: "POST",
url: "/Account/OnWindowClosing"
});
}
};
function onKeydown(evt) {
if (evt != undefined && evt.altKey && evt.keyCode == 115)
{
$.ajax({
type: "POST",
url: "/Account/OnWindowClosing"
});
}
};
window.onbeforeunload = onWindowClosing;
window.document.onkeydown = onKeydown;
4.To add the handler of for the user login and for method invoked in the JavaScript of the step above. In my solution they are in
AcountController
class the methods
LogOn()
and
OnWindowClosing()
.
5.And finally to add the admin pages and the code behind for displaying and managing the collecting data from VisitorLogs table. In my solution they are implemented by the view pages from
Views\VistorLog
folder and by
VisitorLogController
class.