Is there an easy way of obtaining the total page response time in ASP.Net?

安稳与你 提交于 2020-01-24 09:28:33

问题


commonly on say PHP or other web frameworks getting the total response time is easy, just start the timer at the top of the file and stop it at the end.

In ASP.Net there is the whole Page Lifecycle bit though so I'm not sure how to do this. I would like for this response time recording to take place in a master page and the response time show up in the footer of pages. What would be the best way of doing this? Is there something built in to ASP.Net for it? Is it even possible to include the OnRender time?


回答1:


You can do it on the Global.asax, take a look at this article

void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Items["renderStartTime"] = DateTime.Now;
}

void Application_EndRequest(object sender, EventArgs e)
{
DateTime start = (DateTime) HttpContext.Current.Items["renderStartTime"];
TimeSpan renderTime = DateTime.Now - start;
HttpContext.Current.Response.Write("<!-- Render Time: " + renderTime + " -->");
}



回答2:


You can either use

  • Application begin_request and end_request in global.asax
  • Use Firebug at client side to check the time it takes to load the page
  • Use Tracing features

Some information available at:

Measure ASP.NET page load time




回答3:


If you're running Visual Studio Team System (perhaps other versions too now) you can also use the Visual Studio Profiler (http://msdn.microsoft.com/en-us/magazine/cc337887.aspx) to profile what is taking the most time.



来源:https://stackoverflow.com/questions/2962554/is-there-an-easy-way-of-obtaining-the-total-page-response-time-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!