Cumartesi , Haziran 24 2017
Anasayfa / c#.net / ASP.net sayfalarda safya yüklenme süresi

ASP.net 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;
    Thread.Sleep(5000);
    var loadTime = DateTime.UtcNow - start;
    loadTimeLiteral.Text = (loadTime.TotalMilliseconds/1000).ToString(CultureInfo.InvariantCulture);
}

About webbocugu

Check Also

Could not load file or assembly ‘System.Web.Http.WebHost hatası

Asp.net uygulamasına erişmek istediğinizde Could not load file or assembly …… gibi bir hata alıyorsanız uygulamanız hata …

Bir Cevap Yazın

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