views:

174

answers:

1

Hello Everyone

I want to check render time of each page in asp.net mvc application.

i am using asp.net tracing. i have override the OnActionExecuting and OnActionExecuted methods on the BaseController class.

protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string controler = filterContext.RouteData.Values["controller"].ToString();
            string action = filterContext.RouteData.Values["action"].ToString();
            StartTime =System.DateTime.Now;

            System.Diagnostics.Trace.Write(string.Format("Start '{0}/{1}' on: {2}", controler, action, System.DateTime.Now.UtilToISOFormat()));
        }
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            string controler = filterContext.RouteData.Values["controller"].ToString();
            string action = filterContext.RouteData.Values["action"].ToString();
            var totalTime = System.DateTime.Now - this.StartTime;
            System.Diagnostics.Trace.Write(totalTime.ToString());
            System.Diagnostics.Trace.Write(string.Format("End '{0}/{1}' on: {2}", controler, action, System.DateTime.Now.UtilToISOFormat()));

        }

in OnActionExecuted method i get total time. how can i show this time in my http://localhost:51335/Trace.axd report?

Even i had set Trace="true" in <%@ Page %> on every page also.

+1  A: 

Classic ASP.NET uses the following within your aspx code behind: Page.Trace.Write(totalTime.ToString());

In MVC you generally use System.Diagnostics.Trace.Write(... as you have done, so this code is correct.

Try this in your web.config. It routes System.Diagnostics.Trace to ASP.NET tracing:

<system.diagnostics>
<trace>
    <listeners>
       <add name="WebPageTraceListener" 
            type="System.Web.WebPageTraceListener, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </listeners>
  </trace>
</system.diagnostics>

Another thing that you could try is using the Controller.HttpContext.Trace instead. I am unable to test that right now as I am writing this from my phone, so please let me know whether that works.

This page shows you more info on how to make all System.Diagnostics.Trace messages appear un your Trace.axd - http://msdn.microsoft.com/en-us/library/b0ectfxd%28v=VS.85%29.aspx

Daniel Dyson
Thanks @@Daniel... Trace report is creating fine but still i am not able to check page load time in that report.
Pankaj
Are you able to post the Trace Information output from your Trace.axd page? This might help.
Daniel Dyson
yes i am getting Trace.axd page with trace information, but not getting page load time detail
Pankaj
Thanks @@Daniel... its working fine now... thanks for your help
Pankaj