I’m currently developing an ASP.NET application which uses a MasterPage and I want to measure my application webform’s loading time and display that information to the client.
My current strategy involves using the Application_BeginRequest event associated callback (in the Global.asax file of my website solution), to start the measurement of the time spent on the server-side process (as follows)
protected void Application_BeginRequest(Object sender, EventArgs e) {
Context.Items.Add("Request_Start_Time", DateTime.Now);
}
and calculate the elapsed time on the webform’s OnPreRender event associated callback, printing it on a placeholder element (as follows)
protected override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
TimeSpan tsDuration = DateTime.Now.Subtract((DateTime)Context.Items["Request_Start_Time"]);
ExecutionTime.InnerHtml = "<em>Server-side processing duration: " + tsDuration.TotalMilliseconds + " miliseconds.</em>";
}
is this the best way to measure loading time? Is there a more “elegant” way to accomplish this?
Thanks in advance for your time and cooperation.
<%@ Page Trace=”true” %> (or set this in web.config)
Enable tracing and check out the information in trace.axd (in the root of your website).
Then you could set timing points with:
http://msdn.microsoft.com/en-us/library/bb386420.aspx
This is assuming “your client” want deep debug data.