asp.net中怎么计算每个页面的执行时间

发布时间:2021-07-15 16:08:42 作者:Leah
来源:亿速云 阅读:94

asp.net中怎么计算每个页面的执行时间,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

具体分析如下:

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)sender).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 */ }
}

关于asp.net中怎么计算每个页面的执行时间问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

推荐阅读:
  1. shell 计算脚本执行时间
  2. php 计算页面执行时间

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

asp.net

上一篇:ASP.NET中怎么实现一个缓存处理类

下一篇:ASP.NET中怎么为GridView添加删除提示框

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》