Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

28 lines (22 sloc) 0.697 kB
using System.Web.Mvc;
using System.Diagnostics;
namespace ManagedFusion.Web.Mvc
{
public class StopwatchAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var stopwatch = new Stopwatch();
filterContext.HttpContext.Items["Stopwatch"] = stopwatch;
stopwatch.Start();
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var stopwatch = (Stopwatch)filterContext.HttpContext.Items["Stopwatch"];
stopwatch.Stop();
var httpContext = filterContext.HttpContext;
var response = httpContext.Response;
response.AddHeader("X-Runtime", stopwatch.Elapsed.ToString());
}
}
}
Jump to Line
Something went wrong with that request. Please try again.