1: protected void Page_Load(object sender, EventArgs e)
2: {3: //Set ScriptTimeout = 5 sec
4: Server.ScriptTimeout = 5;5: //Sleep 20 seconds
6: System.Threading.Thread.Sleep(20000);7: //Write log
8: using (System.IO.StreamWriter sw =
9: new System.IO.StreamWriter("d:\\temp\\bench.log", true))
10: { 11: sw.WriteLine(12: string.Format("{0:yyyy-MM-dd HH:mm:ss.fff}",
13: DateTime.Now 14: )); 15: sw.Close(); 16: }17: Response.Write("Done!");
18: Response.End(); 19: }
发现,將Server.ScriptTimeout设置5秒无法造成Timeout Exception,后来,又改web.config的<httpRuntime> executionTimeout Attribute,仍然无效。
1) <compliation debug="true" />时候,ScriptTimeout設定會被忽略。
2) 當Timeout小於1分鐘時,实际上將Delay 5-15秒,也就是說executionTimeout=5,實際上可能要15秒才算Timeout。
3) Server.ScriptTimeout是ASP時代的遺跡,屬於COM Interface,不建議使用,在ASP.NET中要設定Timeout時間請改用web.config 的<httpRuntime> executionTimeout屬性。