Changing the response object from OWIN Middleware

后端 未结 3 1655
一向
一向 2020-12-25 12:49

My OWIN middleware is like this. (Framework is ASP.NET Web API).

public class MyMiddleware : OwinMiddleware
{
    public MyMiddleware(OwinMiddleware next) :          


        
3条回答
  •  执念已碎
    2020-12-25 13:12

    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());
            });
    

提交回复
热议问题