本文介绍了测量ASP.NET页面加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我目前正在开发一种使用ASP.NET应用程序中的母版,我想我的测量Web窗体应用程序的加载时间,并显示该信息给客​​户端。

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.

我目前的策略包括使用的Application_BeginRequest 事件相关联的回调(在我的网站解决方案的的Global.asax 文件),开始花费在服务器端处理的时间测量(如下图)

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);
}

和计算的Web窗体的在preRender 事件相关联的回调所经过的时间,在打印一个占位符元素(如下图)

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.

推荐答案

&LT;%@页跟踪=真正的%>(或设置此在web.config中)

<%@ Page Trace="true" %> (or set this in web.config)

启用跟踪和检查出的trace.axd信息(在你的网站的根目录)。

Enable tracing and check out the information in trace.axd (in the root of your website).

然后,你可以设置时间点:

Then you could set timing points with:

Trace.Write("Start time intensive task");
Trace.Write("Stop time intensive task");

这是假设你的客户想深调试数据。

This is assuming "your client" want deep debug data.

这篇关于测量ASP.NET页面加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:36