xport xport - 1 year ago 71
C# Question

How to calculate time elapsed between two consecutive requests?

I am want to develop a quiz site using MVC 2.
A single page will display only one question.
The examinee will select or type the answer and press Next button to proceed.

My business logic on the server side will record the time elapsed between two consecutive page requests. These time stamps must not be tampered with by any means to make a reliable diagnostic report.

What is the best way to handle this?

Answer Source

Well, I wouldn't actually record the time elapsed - I would record the time itself (in UTC). You can very easily go from that to a time between pages, but you can't go the other way. You may well find it's useful to be able to examine particular sessions later on, filtering by when they occurred (e.g. if someone claims to have had a problem at a particular time, you can check whether they were actually on the system).

All you need is some sort of session/user identifier to keep track of the user's session, and you can just record the current time. The timing will be as tamper-proof as the server system clock and the database itself.