I have written a HttpModule that I am using to intercept calls the the WebResource.axd handler so I can perform some post processing on the javascript.
The module wraps the Response.Filter stream to perform its processing and writes it's changes to the underlying stream.
The problem I have is that the script does not get returned to the browser.
So as a really simple example that just acts as a pass through, the module looks like this:
public class ResourceModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PostRequestHandlerExecute += new EventHandler(context_PostRequestHandlerExecute);
}
void context_PostRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication context = sender as HttpApplication;
if (context.Request.Url.ToString().Contains("WebResource.axd"))
{
context.Response.Filter = new ResourceFilter(context.Response.Filter);
}
}
}
and the ResourceFilter that just outputs what it receives looks like this:
public class ResourceFilter : MemoryStream
{
private Stream inner;
public ResourceFilter(Stream inner)
{
this.inner = inner;
}
public override void Write(byte[] buffer, int offset, int count)
{
inner.Write(buffer, offset, count);
}
}
I can attach and see the module and filter being invoked, but when I browse to WebResource.axd url I get nothing back.
I have used this pattern to implement modules that perform processing on aspx pages and they work just fine. It appears there is something about the interaction with the WebResource.axd that prevents this working.