How to intercept response in ASP.NET 5 after all other middlewares? -


in application need add header responses.

however, middleware won't solve me because other middleware sets fresh response, ends pipeline , don't in:

app.use((context, next) => {     context.response.headers.add("myheader", "iscool");     return next(); });  app.usesomeothermiddleware(); // ends pipeline after removing `myheader` 

i can't add middleware after offending one, because pipeline finished.

i add web.config entry it:

but said, needs added almost responses. need teeny bit of logic determine if add it, , web.config solution doesn't afford me that.

so how can in asp.net 5? how can tap pipeline after supposedly finished?

correct implementation rc2

public class custommiddleware {     private readonly requestdelegate _next;     public custommiddleware(requestdelegate next)     {         _next = next;                 }      public async task invoke(httpcontext context)     {         var sw = new stopwatch();         sw.start();          context.response.onstarting((state) =>         {             sw.stop();             context.response.headers.add("x-elapsed-time", sw.elapsedticks.tostring());                         return task.fromresult(0);         }, null);          await _next.invoke(context);     } } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -