Search code examples
asp.net-mvciisloggingmeasure

Measure Execution ASP.NET time without network time


I would like to measure the request execution time of my MVC .NET4.5 App. With IIS logging, the time-taken filed include the network time. (https://support.microsoft.com/en-us/kb/944884) I use IIS7.5 on Windows 2008 R2.

Is it possible (with IIS or another tool) to measure the time from the client request until the IIS response ? (and without waits for the client to acknowledge)

Thanks !


Solution

  • Hmmm sound like to create an action filter ? like this

    public class CheckTimeFilter : IActionFilter
    {
        private Stopwatch stopWatch = new Stopwatch();
    
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            stopWatch.Reset();
            stopWatch.Start();
        }
    
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            stopWatch.Stop();
            var executionTime = stopWatch.ElapsedMilliseconds;
            // Do something with the executionTime
        }
    }
    

    and register this filter to Global filter in `Application_Start()'

    GlobalFilters.Filters.Add(new CheckTimeFilter());
    

    I also would like to suggest you to VISIT and also THIS