Global.asax需要添加的代码。利用我们了解当前页面的运行效率。
代码
![](https://yqfile.alicdn.com/img_1c53668bcee393edac0d7b3b3daff1ae.gif?x-oss-process=image/resize,w_1400/format,webp)
![img_405b18b4b6584ae338e0f6ecaf736533.gif](https://yqfile.alicdn.com/img_405b18b4b6584ae338e0f6ecaf736533.gif?x-oss-process=image/resize,w_1400/format,webp)
protected
void
Application_BeginRequest(Object sender, EventArgs e)
{
Application[ " StartTime " ] = System.DateTime.Now;
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
System.DateTime startTime = (System.DateTime)Application[ " StartTime " ];
System.DateTime endTime = System.DateTime.Now;
System.TimeSpan ts = endTime - startTime;
Application[ " runtime " ] = (Convert.ToDouble((ts.Milliseconds)) / 1000 );
}
{
Application[ " StartTime " ] = System.DateTime.Now;
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
System.DateTime startTime = (System.DateTime)Application[ " StartTime " ];
System.DateTime endTime = System.DateTime.Now;
System.TimeSpan ts = endTime - startTime;
Application[ " runtime " ] = (Convert.ToDouble((ts.Milliseconds)) / 1000 );
}
在要显示的地方: 页面执行时间:单位秒
<%=
Convert.ToString(Application[
"
runtime
"
])
%>