我目前正在开发一个使用a的ASP.NET应用程序,MasterPage我想测量我的应用程序webform的加载时间并将该信息显示给客户端.
我当前的策略涉及使用Application_BeginRequest事件关联回调(在Global.asax我的网站解决方案的文件中),开始测量服务器端进程所花费的时间(如下所示)
protected void Application_BeginRequest(Object sender, EventArgs e) {
Context.Items.Add("Request_Start_Time", DateTime.Now);
}
Run Code Online (Sandbox Code Playgroud)
并计算webform OnPreRender事件关联回调的经过时间,将其打印在占位符元素上(如下所示)
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>";
}
Run Code Online (Sandbox Code Playgroud)
这是衡量装载时间的最佳方法吗?是否有更"优雅"的方式来实现这一目标?
提前感谢您的时间和合作.
asp.net ×1