问题
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