The example in this article describes how ASP.net calculates the time each page executes. Share to everyone for your reference. The specific analysis is as follows:
Here the ASP.net code can calculate the execution time of each page, no need to modify the relevant code of the page, this code will give all pages unified plus execution time display
public class Performancemonitormodule:ihttpmodule {public void Init (HttpApplication context) {context. PreRequestHandlerExecute + = Delegate (Object Sender,eventargs e) {//set Page Timer Star HttpContext RequestContext = ((HttpApplication) sender).
context;
Stopwatch timer = new stopwatch ();
requestcontext.items["Timer"] = timer; Timer.
Start ();
}; Context. PostRequestHandlerExecute + = Delegate (object sender, EventArgs e) {HttpContext HttpContext = ((HttpApplication) Sende R).
context;
HttpResponse response = Httpcontext.response;
Stopwatch timer = (stopwatch) httpcontext.items["Timer"]; Timer.
Stop (); Don ' t interfere with non-html responses if (response. ContentType = = "text/html") {Double seconds = (double) timer.
elapsedticks/stopwatch.frequency; String result_time = String.
Format ("{0:f4} sec", seconds);
Renderqueriestoresponse (Response,result_time);
}
}; } void Renderqueriestoresponse (HttpResponse response, String REsult_time) {Response.
Write ("<div style=\" margin:5px; Background-color: #FFFF00 \ ""); Response. Write (String.
Format ("<b>page generated in" + Result_time)); Response.
Write ("</div>"); public void Dispose () {/* not needed/}}
I hope this article will help you with your asp.net programming.