Is there a backend-exclusive solution for scheduling periodic function calls without using JavaScript?

In the JavaScript file that I have included in the main .cshtml page of my ASP.NET MVC application, the following code can be found:

var ajax_call = function () {

    $.ajax({
        type: "GET",
        cache: false,
        url: "/Session/Index/",
        success: function (result) {
            if (!(result.length > 0)) {
                window.location.href = '/Home/Index/'
            }
        }
    });
};

var interval = 1000 * 60 * .2; // X minutes---.2 -> every 12 seconds

setInterval(ajax_call, interval);

The purpose is to verify the validity of the session (the SessionController only returns a result when the session is active). If the session is not valid, the browser is redirected to Home/Index, where HomeController has a global authorization attribute that redirects to the login page for invalid sessions.

My questions are: Is this approach appropriate? It appears to work as intended, but is there a way to achieve the same functionality entirely on the server side?

Thank you.

Answer №1

The main objective is to verify the validity of the session.

Implementing a method where a request is sent to the server will reset the session timeout to zero, essentially keeping the session active indefinitely. This poses a security risk as it allows unauthorized access if a user forgets to log out and leaves their computer unattended.

Inspired by the security measures used in banking and credit card websites, I have implemented a different approach on my own websites.

By default, the Session Time out period is set at 20 minutes (this can be adjusted according to preference). I allow a timer to run on the client side, and when it reaches 19 minutes, a popup message with a countdown timer is displayed.

https://i.sstatic.net/vK6dr.png

If the user fails to close the popup within the designated time, they are automatically redirected to the logout page.

For further information and sample code demonstrating this concept, you can refer to this link. Please note that you do not necessarily need to utilize Telerik controls to achieve the desired functionality.

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

Displaying Props Information in a Modal Window using React

Currently venturing into the realm of React JS, where I am in the process of developing a sample eCommerce application for real-time use. However, I have hit a roadblock. In my Products List, there is a Buy button for each product. When clicking on this b ...

"When using Laravel 5.2, be cautious when adding new elements to an existing session array as it may accidentally

I'm struggling to save basket data in a Laravel 5 session using AJAX. Whenever I try to add an item to the 'basket' array stored as the session value, it keeps getting overwritten. Here is my controller method: public function add(Request ...

I am currently facing a challenge in animating my ng-show/ng-hide animation

This particular issue has been widely recognized and discussed multiple times in various forums. Despite the extensive search, I have not come across satisfactory solutions. var aniApp = angular.module("aniApp", []); aniApp.controller('mainCtrl&ap ...

Encountering numerous errors during npm installation in a react project

Struggling with React as I try to navigate through course files and run npm install, only to be bombarded with countless errors and warnings on every single file. I've double-checked my directory and ensured the presence of a json file. gyp ERR! ...

In Vue, applying CSS styles to D3's SVG elements may not work as expected when using the scoped attribute

Here is the code snippet of my component: <template> <div id="something" class="card"> </div> </template> const height = 200; const width = 200; let graph = d3 .select('#something') .append('svg') ...

Issues with sending form data to controller using AJAX in Laravel

I'm currently working on a form in Laravel that enables users to purchase products dynamically without needing to refresh the page. While I am successfully able to initiate the AJAX function, I am encountering an issue where the data is not being post ...

Ways to execute a JavaScript function upon a button click instead of during the page load completion

I searched on Google but couldn't find the answer, so I'm asking here for help. In the attached screenshot located at the end, when the user clicks on the download button, some backend actions are performed such as file transfer. Once the proces ...

Integrating specific data entries into a Sencha Touch store

I've been struggling with this issue for quite some time now. It may seem trivial, but I just can't seem to figure it out. My goal is to create a store and gradually populate it with records based on user interface actions. For example, clicking ...

The CSS file is failing to recognize the changes made to the data-theme attribute in the HTML

Currently implementing a dark theme on my website involves adding a toggle switch to the footer.html page, which adds a variable named data-theme = 'dark' to the html. The scss files of the footer and core are adjusting accordingly based on the c ...

You cannot use a relative path when inserting an image tag in React

I am having an issue with my img tag not loading the desired image when using a relative src path in my React project. When I try: //import { ReactComponent } from '*.svg'; import React from 'react'; import firebase from "./firebas ...

Tips for dynamically resetting the dataTable

When I create a datatable and add rows dynamically based on the selected option, I encounter an issue where I need to reinitialize the dataTable every time the option is changed. To address this, I have placed the reinitialization code inside the $("#selec ...

Tips for utilizing JSON.parse

Within my ajax request, I am encountering the following code: 403: function(jqXHR) { var error = jqXHR.responseText; console.log(error); } When this error occurs, a message is displayed in the console: Htt ...

Is there a way to extract information from the HTML source code of an external website and display it in my application?

Seeking a method to search an external URL for content that matches "title" and then display the results on my HTML page using Javascript. Despite my efforts with Javascript, I have not come across any resources that address this issue. Could it be that I ...

Retrieve a particular element from a JavaScript object by iterating through it with the .each()

Welcome, fellow developers! I am currently facing a challenge in my ticketing system project involving getting the 'title' variable from a node.js loop. The objective is to use this variable as a placeholder so that when a user wants to edit a t ...

Instructions for converting a readonly text field into an editable one using JavaScript

I'm trying to make it so that when the button (with id name_button) is clicked, the text field (with id name_text_field) becomes enabled. However, my current code doesn't seem to be working. Here's a snippet of my HTML: <input type="tex ...

$injector encountered a problem resolving the required dependency

Currently, I am attempting to adopt the LIFT protocol (Locate, Identify, Flat, Try(Dry)) for organizing my Angular projects. However, I am encountering difficulties in handling dependencies from other files. Here is the factory I have: (function () { ...

Is it possible to combine the outcomes of a SQL query that produces numerous entities with identical identifiers?

Currently working on my first Node.js API project. Within the '/posts' endpoint, I am receiving data in this format: [ { "POST_ID": 1, "POST_TITLE": "Post N.1", "POST_DESCRIPTION" ...

Choose a single conditional element by using the .each method in JavaScript

I am looking to choose just one article that meets a specific condition. In my code, I am using hourDiff==0 as the condition to be true. I am using the 'each' function to loop through the articles. I have set display:none for all articles in the ...

Advantages of placing script src tags at the top of the body versus placing them at the bottom of the body

I've heard that it's best to place the script tags right before the closing body tag. However, when I follow this advice, my angularJS expressions don't seem to compute correctly for some reason. When I place the script tags in that location ...

VueJS advisory: Refrain from directly altering a prop

When attempting to modify a prop value using the @click directive, I encountered a warning message: [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed pr ...