如何显示它采取产生一个页面在页面页脚中的时间? [英] How do I display the duration it took to generate a page in a pages footer?

查看:147
本文介绍了如何显示它采取产生一个页面在页面页脚中的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试版本,我想表明它花了时间,服务器端生成的页面页脚的页面。

During debug builds I would like to show the duration it took, server side, to generate a page in the pages footer.

所以,举例来说,如果一个页面需要250ms的服务器端,我想在页脚显示,在调试版本。我如何在ASP.NET MVC项目实现这一目标?

So for example if a page takes 250ms server side I would like that displayed in the footer, in debug builds. How can I achieve this in an ASP.NET MVC project?

推荐答案

在你的母版页一下添加到页脚:

Add this to the footer in your master page:

Page rendering took <%= DateTime.Now.Subtract( this.ViewContext.HttpContext.Timestamp ).TotalMilliseconds.ToString() %>

您还可以在扩展方法把这个包起来:

You can also wrap this in an extension method:

public static class Extensions
{
  public static string RequestDurationinMs( this HtmlHelper helper )
  {
    #if DEBUG
    return DateTime.Now.Subtract( helper.ViewContext.HttpContext.Timestamp ).TotalMilliseconds.ToString();
    #endif
  }
}

使用,像这样:

<%= Html.RequestDurationinMs() %>

您可能需要导入扩展类的命名空间:
&LT;%@导入命名空间=Your.Namespace%GT;

You may need to import the namespace of the extensions class: <%@ Import Namespace="Your.Namespace" %>

这篇关于如何显示它采取产生一个页面在页面页脚中的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆