EasyHostingASP.NET | Best and cheap ASP.NET 4.5 hosting. In this article, I showed you how to use Page Instrumentation, a new  feature in ASP.NET 4.5 which might be useful for you during debugging.
ASP.NET 4.5 include a hidden gem called Page Instrumentation, very few people aware of this gem. You can use page instrumentation in ASP.NET 4.5 WebForm and MVC 5 or 4(assuming it targets 4.5). It allows you to inspect/instrument a web form or a mvc view during the rendering process. Page instrumentation are useful in scenarios when you have some performance issues regarding view engine rendering. In this article, I will show you how to use this feature in ASP.NET 4.5.

Best and Cheap ASP.NET Hosting in Australia Click Here !

To start instrumenting a page, you need to inherit PageExecutionListener class.

1cde

The BeginContext will be called by a view engine before it renders the output for the specified context. Similarly, EndContext called by a view engine after it renders the output for the specified context. Both of these methods accept PageExecutionContext class as a parameter which have the following members.

2cde

All the properties of PageExecutionContext class are self explanatory. Let assume we have the following MVC view(for understanding how many times and when the BeginContext and EndContext will be invoke by the framework).

3cde

The Razor View Engine will emit the following C# code

4cde

Finally, here is a simple implementation of PageExecutionListener class which calculates the total time each time whenever something is written to the output response.

5cde

Alexia Pamelov

Alexia Pamelov

My name is Alexia Pamelov and I have spent the past 3 years building money making blogs review. Since then I have launched lots of successful nice blogs and after selling my survivalist blog I decided to teach other people how to do the same.
Alexia Pamelov