①在Global.asax.cs文件中
protected void Application_BeginRequest(Object sender, EventArgs e) { Application["StartTime"] = System.DateTime.Now; }
②在 TestName.aspx.cs文件中
private void Page_Load(object sender, System.EventArgs e) { System.DateTime startTime = (System.DateTime)Application["StartTime"]; System.DateTime endTime = System.DateTime.Now; System.TimeSpan ts = endTime - startTime; Response.Write("页面执行时间:" + ts.Seconds + "秒," + ts.Milliseconds + " 毫秒"); Response.Write("页面执行时间:" + ts.TotalSeconds + "秒"); Response.Write("页面执行时间:" + ts.TotalMilliseconds + "毫秒"); }