Pazartesi , Şubat 26 2024
Anasayfa / / sayfalarda safya yüklenme süresi sayfalarda safya yüklenme süresi

A little heads up, this solution will not work if you have an ASP.Net AJAX UpdatePanel on your page. The javascript which is loaded by ASP.Net AJAX will throw an error. Of course you’re better off throwing out ASP.Net AJAX and just use plain AJAX calls. But if that’s not possible, be warned.

A common feature that gets requested on a lot of big web applications is to show the time it took to load the page. Sometimes it’s just to show to the user how long a certain action took, other times it’s to have a ballpark number when performance issues arise.

First things first, how can the load time of a page be measured? There are different ways of measuring. You can use DateTimes, you can use StopWatch and they all have advantages and disadvantages. For this post DateTimes will suffice, we’re looking for a ballpark number.

I was surprised how difficult it was to implement this in ASP.Net Web Forms. For a simple one page project the solution is quite straight forward. You take the page where you want to show the load time and when the Page_Load has finished you subtract the DateTime that was initialized at the beginning of the method from the DateTime that was initialized at the end. The code hopefully speaks for itself:

protected void Page_Load(object sender, EventArgs e)
    var start = DateTime.UtcNow;
    var loadTime = DateTime.UtcNow - start;
    loadTimeLiteral.Text = (loadTime.TotalMilliseconds/1000).ToString(CultureInfo.InvariantCulture);

About webbocugu

Check Also

chrome bilinmeyenler

Yeni işlevleri etkinleştirin Adres çubuğuna chrome://flags yazarak grafik hızlandırma gibi Chrome’un deneysel işlevlerini etkin hale …

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir