My OWIN middleware is like this. (Framework is ASP.NET Web API).
public class MyMiddleware : OwinMiddleware { public MyMiddleware(OwinMiddleware next) :
I used this code to get the time taken by every request.
appBuilder.Use(async (context, next) => { var watch = new Stopwatch(); watch.Start(); await next(); watch.Stop(); context.Response.Headers.Set("ResponseTime", watch.Elapsed.Seconds.ToString()); });