简体   繁体   中英

Sharing a Single Class Across Master Page, Page, and all User Controls

I would like to check the load speed of each page in a particular asp.net website (based on C#). I thought of creating a class for timing the loading and execution of a certain element. I'd like to create a stopwatch object on each user control and on the page itself to get diagnostics on how long the page takes to load altogether. When debug is enabled, we could then see the load times of each of the pages, as well as each of the elements.

I don't want to save it in session , but I really can't think of a way around it.

I was thinking that a nice implementation would be to include a class that I write which will track the stopwatch values for each of the master page, page, and user controls as they load, but where could I save each execution time when it was done? I suppose I could use Session , but is this the only way to save data across user controls and pages?

What would be the best way to do this?

I would use a logging framework like log4net etc... Especially since you're only doing it for debug mode. You can define warning levels to match your loading speeds if something is slower than expected...

Besides using a logging framework you could use the tracing you need by using the ASP.nets out of the box tracing and diagnostic features [http://msdn.microsoft.com/en-us/library/bb386420.aspx] or you could use something like elmah for other needs. Try not to re-invent the wheel but make a car out of it that flies. Good luck!!

If this is an MVC site, you could check out the MVC Mini Profiler . It is available as a Nuget package .

我同意其他答案,因为在执行相关逻辑时利用日志记录实现就足够了,例如在Unload()页面上写入日志。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM