asp.net計(jì)算每個(gè)頁面執(zhí)行時(shí)間的方法
本文實(shí)例講述了asp.net計(jì)算每個(gè)頁面執(zhí)行時(shí)間的方法。分享給大家供大家參考。具體分析如下:
這里的asp.net代碼可實(shí)現(xiàn)計(jì)算每個(gè)頁面的執(zhí)行時(shí)間,無需要修改頁面的相關(guān)代碼,這段代碼會(huì)給所有的頁面統(tǒng)一加上執(zhí)行時(shí)間顯示
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 */ }
}
希望本文所述對(duì)大家的asp.net程序設(shè)計(jì)有所幫助。
相關(guān)文章
ASP.NET?MVC開發(fā)接入微信公共平臺(tái)
這篇文章主要為大家介紹了微信平臺(tái)開發(fā)ASP.NET?MVC接入微信公共平臺(tái)實(shí)現(xiàn)過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04
ASP.NET開發(fā)者使用jQuery應(yīng)該了解的幾件事情
如果你是有著APS.NET開發(fā)背景的人員,那么jQuery的幾個(gè)概念建議你應(yīng)該忘掉。像使用其它的framework一樣,你應(yīng)該學(xué)習(xí)一下jQuery的所有語法等約定來讓它更好的為你服務(wù)。2009-09-09
數(shù)據(jù)庫 數(shù)據(jù)類型float到C#類型decimal, float數(shù)據(jù)類型轉(zhuǎn)化無效
數(shù)據(jù)庫 數(shù)據(jù)類型float到C#類型decimal, float數(shù)據(jù)類型轉(zhuǎn)化無效的解決方法2009-07-07
.Net Core 之 Ubuntu 14.04 部署過程(圖文詳解)
本篇文章主要介紹了.Net Core 之 Ubuntu 14.04 部署過程(圖文詳解),有興趣的可以了解一下。2016-11-11
集合類List與Dictonary實(shí)例練習(xí)
本文將詳細(xì)介紹下List<>泛型集合/Dictonary<>字典/泛型集合練習(xí) /中日期轉(zhuǎn)換提取為方法以及泛型集合練習(xí)之翻譯軟件,感興趣的你可不要錯(cuò)過了哈2013-02-02
MVC使用MvcPager實(shí)現(xiàn)分頁效果
這篇文章主要為大家詳細(xì)介紹了MVC使用MvcPager實(shí)現(xiàn)分頁效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
ASP.NET?Core基于現(xiàn)有數(shù)據(jù)庫創(chuàng)建EF模型
這篇文章介紹了ASP.NET?Core基于現(xiàn)有數(shù)據(jù)庫創(chuàng)建EF模型的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04

