Implementing a server-side timer in ASP.NET MVC to restrict users from modifying the timer

In my MVC asp.net quiz application, users are given a variable amount of time to complete the quiz. Once this time runs out, their answers will be automatically submitted.

As of now, I have set up a timer in Javascript with the duration stored in the Controller's Session["EndTime"]. However, there is a concern that users may tamper with the Javascript code and manipulate the timer. Is there a way to initiate the timer in the Controller and trigger an Action once it expires?

Answer №1

It is not within the server's ability to compel the browser to submit data; that task falls under the jurisdiction of JavaScript code. Users maintain the freedom to alter this process as they see fit.

Instead, the server focuses on monitoring two key elements:

  • An exclusive identifier for each instance of the "test"
  • A timestamp marking the beginning of the test (or its expiration time, as both hold equal significance)

The initial value is embedded in the form transmitted to the browser as a hidden field. When the user submits test results, the server-side script utilizes this identifier to cross-reference it with the saved timestamp, checking for timely completion. Should the submission exceed the stipulated timeframe, the server will dismiss the data and report an error.

In essence, while the server cannot enforce immediate result submission from users, it retains the power to reject belated responses.

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

Node - ensure that each API call finishes before initiating the next one

Currently, I am encountering an issue with my POST request within the 'add-users' route. I have initialized an array named success and aim to trigger the next API call once a response is received. It seems that the problem lies in sending too ma ...

The animation using Jquery and CSS is experiencing some glitches on Safari when viewed on an

Why is smooth animation not working on iPad Safari with jQuery animate? $('#myId').css({ 'left': '-100%' }).animate({ 'left': '0' }, 300, 'linear'); I also tried using the addClass option and in ...

Tips for verifying a text input as an email address using JQuery

Can someone help me with writing an if statement that checks if two fields are empty and confirms if one of them is a valid email address? Also, how can I validate if the email address entered is indeed valid? var fullname = $("#name").val(); var emai ...

Unable to Transmit Authorization Header in Cross-Domain Access Situation

My Node.js server has cross-origin communication enabled, allowing my Vue application to access its API from a different origin where static assets are served. This is achieved by setting the following code in Node.js: res.setHeader('Access-Control-Al ...

Can saving data within a mongoose pre-save hook initiate a continuous loop?

Currently, I am developing an API for a forum system which includes functionalities for users, forums, and posts. In my MongoDB Database, there is a 'categories' collection where each category acts as a container for a group of forums. Each categ ...

Send the canvas image dataURL for decoding and saving on the server using AJAX in conjunction with PHP

In the front-end, an image is generated (canvas.toDataURL) from the content of a div: ... var img = new Image(); var dataUrl; img.onload = function() { ...

I am trying to understand why my React component's render function is being called twice - first without any data and then again with data, resulting in a

I am facing an issue with my TreeNav component, where the data is fetched from an API call. I have set up the reducer, action, and promise correctly, but when I try to map over the data in the component render function, I get an error saying "Uncaught Type ...

Unable to retrieve HTML code from a webpage using its URL address

Currently, I am trying to retrieve the HTML code of a specific webpage located at . My initial attempts using HttpClient were unsuccessful due to exceeding request processing time. It seems like this website may have anti-bot protection in place. I attempt ...

What is the procedure for passing arguments to Google signIn in a NextJS backend?

I am currently working on implementing a role-based Google sign-in feature in a Next.js 13 app using next-auth. This setup involves calling two different tables to create users based on their assigned roles. For the database, I am utilizing mongodb/mongoo ...

The functionality of Wow.js seems to be malfunctioning. Could this be due to incorrect initialization or script calls?

I'm facing some difficulties implementing wow.js into my HTML code. Could it be due to missing script loads or incorrect script loading? Is there a chance I'm not initializing wow.js properly? Although the nav part won't be utilizing animati ...

I currently possess a certain document stored in the database. Is there a way to create a query using mongoose that will allow me to remove an item from the "cart" array within this document?

In this post request, the intention is to remove the item from the "cart" array by identifying it with the product "id". .post('/delete', async (req, res) => { if (await UserProfile.findOneAndDelete({ 'cart.id': req.body.id })) { ...

Tips for implementing live camera feed in reactJs

UPDATE I attempted to make changes in the code by using srcObject, however, it did not produce the desired result as expected. componentDidMount() { navigator.mediaDevices.getUserMedia({ video: true, audio: true }) .then( stream => { ...

How can I successfully link a form collection to a specialized model object that relies on two custom objects in ASP.NET MVC?

My attempt at a simple task seems to be causing some confusion. I have a details page with a custom model class that uses multiple custom objects, one of which has another custom object as a property. The page displays information and allows users to post ...

ClassSerializerInterceptor in NestJS does not show the _id field

I am encountering an issue with properly exposing the _id when using the Serializer. Here is my current setup: @UseInterceptors(ClassSerializerInterceptor) @SerializeOptions({ strategy: 'excludeAll' }) This is how I defined the Class: export cl ...

Obtaining a Buddypress user's name through a JavaScript file

When working with my buddypress PHP templates, I typically fetch the username of a user using their ID like this: <?php echo bp_core_get_username( '{{userID}}' ) ?> However, I now need to access the username from an external JavaScript fi ...

The form cannot be submitted within the ajax success function

I have a contact form with Google reCAPTCHA. I need to validate the captcha before submitting the form, but even though my jquery code validates it correctly, I am unable to submit the form when the result is true. jQuery('#citygreen-contact-us-submi ...

Encountering CORS Issue when attempting to upload a file from an external URL using Angular

I am attempting to upload a file from an external URL, but I keep encountering a CORS error when trying to access the external URL. await fetch(url).then(function (res) { response = res; }).catch(function () { setTimeout(() => { this.toaster. ...

Unable to export data to Excel on the primary server

Hey everyone, I'm currently facing an issue with exporting to Excel in asp.net. I am able to export Webgrid data to an Excel sheet successfully on localhost, but when deployed on the main server, it doesn't work. I am utilizing Microsoft.Office. ...

Node.js backend includes cookies in network response header that are not visible in the application's storage cookies tab

I am currently working on creating a simple cookie using express's res.cookie() function. However, I am facing an issue where the cookies are not being set correctly in the application tab. My project setup includes a React frontend and a Node backend ...

Ngrx/effects will be triggered once all actions have been completed

I've implemented an effect that performs actions by iterating through an array: @Effect() changeId$ = this.actions$.pipe( ofType(ActionTypes.ChangeId), withLatestFrom(this.store.select(fromReducers.getAliasesNames)), switchMap(([action, aliases ...