Reputation: 815
I have a MVC asp.net quiz application. You have a variable amount of time to take the quiz, and if time runs out, then the answers are automatically submitted.
Currently, I have the timer setup in Javascript, with the amount of time being held in the Controller - Session["EndTime"]
. But, my understanding is that a user can edit the Javascript and change the timer when it is implemented in Javascript. If true, how do I run the timer in the Controller and send an Action once the timer runs out?
Upvotes: 1
Views: 761
Reputation: 218930
The server can't force the browser to submit anything, that's what the JavaScript code would do. And, yes, the user can choose to modify that if he or she wants.
What the server would do is keep track of two things:
The first value is included in the form sent to the browser, basically just a hidden form field. When a test result is posted to the server, the server-side code uses the identifier to look up the persisted date/time stamp to compare it with the current date/time. If more time than expected has elapsed, reject the test results with an error.
Basically, the server-side code can't force the user to submit the results. But it can reject results which aren't submitted in time.
Upvotes: 3