倒计时
服务器端:
在用户登陆后必须设置
int delay=5; //假定允许延时5分钟。
Session["CheckPoint"]=DateTime.Now.AddMinutes(60+delay);
Session.Timeout必须大于考试的时间
3。当用户交卷后比较提交时间和Session["CheckPoint"]的值,看是否超时。
4。不要用Cookie,因为普通Cookie是明文的,高手可以在客户端改Cookie。
用ASP.NET的话,一定加上在服务器端验证,以防作弊。
<script language="C#" runat="server">
void Page_Load(Object o, EventArgs e)
{
int nCounter = 0;
if (Session["counter"] != null)
nCounter = (int)Session["counter"];
if (nCounter < 10 )
{
SomeMethod(nCounter);
nCounter++;
Response.AddHeader("Refresh","5"); //refresh every 5 seconds
}
Session["counter"] = nCounter;
}
void SomeMethod(int n)
{
//depending on the value of n, you can any method you want
label1.Text = String.Format("I am being called the {0}th time at {1}", n, DateTime.Now);
}
</script>
<form runat="server">
<asp:label id="label1" runat="server" />
</form>
浙公网安备 33010602011771号