Display User Login Time Information

I am currently facing a challenge with displaying user log in time details. I have two tables set up for this purpose - UserMaster, which contains UserDetails, and UserLogInTimeDetails, which includes columns for UserId and LogedInTime. Whenever a user logs in, their UserId and LogInTime are stored in the UserLogInTimeDetails table. However, when a user logs off, I delete the corresponding row from UserLogInTimeDetails.

The issue arises when a user closes their browser without logging off. In such cases, the user's details remain in the UserLogInTimeDetails table, preventing them from being able to log in again.

I have searched online and found that handling browser close events is not feasible. Many sources suggest using the onbeforeunload event, but unfortunately, it has not been effective in my situation.

If anyone could provide assistance or solutions to this problem, it would be greatly appreciated. Thank you.

Answer №1

One potential solution could be to utilize the Session_End function in your global.asax file to automatically remove a user when their session expires. While there may be some uncertainty about retrieving the session ID from this method, it's worth exploring further within the EventArgs...

void Session_End(Object sender, EventArgs e) {
    //Code to remove user from database would go here
}

Alternatively, you could consider tracking user activity based on their last interaction. Each time a user interacts with your system, update the timestamp of their last activity. This information could be stored in the database alongside their login time and session ID, allowing you to calculate the duration of their active session.

Answer №2

Using SignalR is the top choice for monitoring user activity and status, whether they are online or offline. By capturing events like disposal, you can accurately track when a user logs out or closes their browser.

This method may introduce you to new concepts. Take a look at the link below for a straightforward example of how SignalR works.

Check out this signalR sample application for monitoring online and offline statuses

Answer №3

Is it necessary to restrict users from logging in multiple times on different browsers?

If not, a common approach is to store login information in a session variable (such as login time or user id) and use it to determine if the user is logged in.

If the user closes the browser, the session is lost, requiring them to log in again. However, they can log in multiple times from different browsers.

You can access these variables like so:

// Set it like this. Can be any type of object with login data.
Session["LoginData"] = "Hello";

// Get it like this.
string test = (string)Session["LoginData"];

Edit: If it is crucial to prevent users from logging in multiple times, there is a more complex issue to address. Perhaps a solution like this could work?

  • Have the browser (via ajax) ping the web server at intervals to track activity.
  • When the server receives a ping, record the date and time in a session variable.
  • Before allowing access to the webpage, check the session for recent pings to determine if the user is already logged in elsewhere.

I hope this solution is helpful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The value of YOUR_VARIABLE in the Node.js process environment appears to be undefined

Having trouble hiding a discord token for my bot, even though I believe dotenv is set up correctly. However, all I keep getting back is undefined. I've gone as far as using nodemon to refresh the server when making changes, but the issue persists. Co ...

It is not possible to invoke a function within the mounted() lifecycle hook

I recently integrated a chat API into my Vue.js project for connecting to chat rooms. Upon entering a chat room page, an ajax request is triggered which then calls a function responsible for fetching the complete chat history: mounted() { $.ajax({ url: ...

Component styled with ReactJS

As a newcomer to reactjs, I recently created a component that looks like this: <Row> <Column className="col-8 noPadding"> <Text value={this.props.description} /> </Column> <Column className="col-4 text-rig ...

How to properly structure an array in JSON format for utilizing in the Google Charts API?

Noticed that integer values need to be integers in the json, however I am using strings. The original array structure is as follows: '[{"sctr":"Asset Managers","amount":"1586500"},{"sctr":"Auto Parts","amount":"1618000"},{"sctr":"Business Su ...

Securing socket.io connection in a nodejs application

I'm currently developing a chat application that utilizes sockets for bi-directional message sharing. Although the socket is functioning properly, I would like to implement user authentication before granting access to the socket connection. I'v ...

The issue with Server.Transfer not functioning properly within the Application_Error handler

I need to redirect to an Error 404 page and ensure that a 404 response code is issued for Google's search engine to handle. Unfortunately, we are stuck using IIS 6 in our production environment. :( The code responsible for handling 404 errors is loc ...

What is the best way to dynamically swap out an image within an element?

Is there a way to dynamically replace this image without deleting the HTML SVG element and re-rendering it? xlink:href="http://missosology.info/forum/download/file.php?avatar=11666_1307312313.jpg" CODE: https://jsfiddle.net/bfv17f0e/ <svg class="clip ...

Incorporate a personalized object by adjusting its properties to align with the JSON object through JavaScript or Node.js

const info = [ { system: { id: "4gSSbjCFEorYXqrgDIP2FA", type: "Entry", content: { type: { name: "Author" } }, }, DataDetails: { shortSlugOption: { "en-us": "some value", "za-op": "random value" }, mediaFileAsset ...

Discover the color value within an array that begins with the "#" symbol

In my PHP code, I have written a function that extracts values from a CSS file and creates an array. Now, I need to loop through this array and create another array that only contains color values (strings starting with #). The challenge is that the length ...

Link the <select> element with ng-options and ng-model, ensuring that the model contains a composite key

I am facing a challenge with my Angular service that retrieves a list of objects with a composite key comprising two parts. I am struggling to write the bindings in a way that properly re-binds existing data. Below is my current attempt: angular.module( ...

Issue with Mobile NavBar remaining visible after clicking on target element in HTML CSS

On my website, everything works perfectly with the Nav bar except for when I am on mobile. When I click on any href from my Nav Bar, it directs me to the correct location but does not close the Nav Bar afterward. I need it to function this way: After click ...

I’m keen on utilizing JQuery with Node.js and EJS, but I’m encountering an issue where $ is not

I attempted to incorporate JQuery in my project by following these steps. Installed jquery using npm install Modified the package.json file Despite this, the functionality still does not work as intended. Below is a snippet of the .ejs page: <html& ...

Always ensure that only one div is visible at a time

I am currently working on a project where I cannot use ng-cloak due to the way the css files are loaded. I have been exploring alternative solutions and have tried a few different approaches. My main goal is to ensure that two icons are never shown at the ...

There are times when the `window.location.replace` function does not

I have implemented a Bootstrap Dropdown feature that allows users to select a language for site translation, append the URL with the selected language, and then reload the page. Initially, it works well for the first set of translations like en|es. Howeve ...

The dilemma of maintaining order with an async loop nested within a promise

Prior to displaying the page, it is crucial that all data fetched from the API call is stored in the database. let saveUsersToDB = function () { // Function to fetch users return getAllUsers.then((data) => { // Function ...

Surprising results from implementing the useLocation() hook in a React application

Currently, I am embarking on a personal endeavor to create an online auction platform. One of the key functionalities I am working on is rendering detailed product information when a user clicks on a specific product for purchase. Initially, everything wor ...

Problem concerning the distinction between local and global scope as well as the presence

I have this code snippet for creating a calculator: const numbers = document.querySelector('.numbers') const display = document.querySelector('.display') const functions = document.querySelector('.functions') const equalClear ...

canvasJS: unable to load the chart

This is my first time using canvajs, but unfortunately, it's not working as expected. Can someone please review my code? data.php <?php header('Content-Type: application/json'); include './traitement.php'; $data =array(); ...

Streaming through Janus with Vue.js

I successfully ran Janus on a server with no issues, but I'm currently facing some challenges in figuring out how to stream on the Janus server. Despite my searches, I have not been able to locate any code snippets. I am working on a pr ...

Express app encountering an error when trying to read an undefined property

Currently, I am in the process of learning how to develop a blog website using Node.js, Express, and ejs. As I attempted to render the "show" page, I encountered the following error: The similar problem Prior to this, I also faced an error stating "cannot ...