Salı , Ekim 17 2017
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

HTML5 ile Sadece Sayı, Rakam Girilen Input Yapmak

HTML5’in getirdiği yenilikleri kullanarak sadece sayısal değerlerin girildiği bir input alanı oluşturacağız. Input alanına sadece …

Bir Cevap Yazın

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