title: ASP.NET OWIN Middleware - modify HTTP response
body: <p>I need to <strong>intercept</strong> all the <strong>aspx</strong> and <strong>js</strong> file requests and to <strong>replace some text labels</strong> if they are present. This middleware should work as an IIS module, obviously without interfering with the normal flow of the web application. 
  I wrote some code but I have no idea how to do it.</p>
  
  <pre><code>public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          app.Use(typeof(FilterMiddleware), Console.Out);
      }
  }
  
  public class FilterMiddleware : OwinMiddleware
  {
      private readonly TextWriter logger;
      private readonly OwinMiddleware nextMiddleware;
  
      public FilterMiddleware(OwinMiddleware nextMiddleware, TextWriter logger) : base(nextMiddleware)
      {
          this.nextMiddleware = nextMiddleware;
          this.logger = logger;
      }
  
      public override async Task Invoke(IOwinContext context)
      {
          var headers = context.Request.Headers;
  
          // IF .js OR .ASPX REPLACE TEXT HERE //
  
          await nextMiddleware.Invoke(context);
      }
  }
  </code></pre>