c# - After how much time page loaded -


i'm trying create code in c# find how time takes website load. (not in specific web browser.) can me? thanks

if want record how long takes basic page source, can wrap httpwebrequest around stopwatch. e.g.

    httpwebrequest request = (httpwebrequest)webrequest.create(address);      system.diagnostics.stopwatch timer = new stopwatch();     timer.start();      httpwebresponse response = (httpwebresponse)request.getresponse();      timer.stop();      timespan timetaken = timer.elapsed; 

however, not take account time download content, such images. have dig deeper , question had no code can not guide anymore down path. example work if want source minimalistic code.

you can log information if turn on trace

if have control on asp.net page, turn on trace. there bunch of information page lifecycle( including time stamps), , other useful profiling information.

turn on trace page in page directive @ top of aspx file:

<%@ page trace="true" %> 

or dynamically in code:

trace.isenabled = true; 

or globally in app setting in web.config:

<configuration>  <system.web>   <trace enabled="true" requestlimit="40" localonly="false"/>  </system.web> </configuration> 

you can use tool microsoft's logparser or other read xml trace file. use trace listeners within code. thought :)


Comments