Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
Hi... I'm Ibrahim..,
Can anyone suggest step by step to write the code for to find user login and logout time to trace user(log report of user)..?
Posted

1 solution

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.
JavaScript
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) //Alt + F4 
            {
                $.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.
 
Share this answer
 
v2
Comments
Agasimani 5-Jul-14 15:13pm    
sorry i'm fresher in asp.net i know asp.net with c# only so can you guide me with c#..
Raul Iloc 6-Jul-14 2:33am    
The steps (presented above), the JavaScript, the database table, and the logic are the same for ASP.NET. Some differences are only the UI part but the main idea are in the steps and the JavaScript above!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900