1
Vote

Content is duplicated or triplicated when a blank HttpModule is present

description

Source: http://stackoverflow.com/questions/14777337/imageresizer-net-with-cache-plugin-causing-duplicate-output-cache

Reproduce by creating a blank HttpModule which adds a no-op event handler to PreSendRequestHeaders
public class BlankModule : IHttpModule {

    void IHttpModule.Init(System.Web.HttpApplication context) {
        //Having any event handlers registered for this event causes cache duplication during the Filter execution
        context.PreSendRequestHeaders -= context_PreSendRequestHeaders;
        context.PreSendRequestHeaders += context_PreSendRequestHeaders;
    }
    void IHttpModule.Dispose() { }
    protected void context_PreSendRequestHeaders(object sender, EventArgs e) {}
}
Make sure you register it in Web.Config:
   <system.webServer>
     <modules>
       <add name="BlankModule" type="BlankModule"/>
     </modules>
   </system.webServer>
Place a breakpoint on OutputCacheFilter.cs after the following lines of code, and you can inspect the response duplication directly (it's also visible in-browser)
        response.Flush();
        var output = _filter.GetContents(response.ContentEncoding);

Register another copy of the module, and you'll get tripled responses, not just doubled.


This prevents ImageResizer (http://imageresizing.net) from being used with Contrib.Cache.

comments

urbanit wrote Jul 3, 2013 at 2:53 PM

Is there any solution available?

sebastienros wrote Jul 9, 2013 at 5:41 PM

I have tried with the latest 1.x tip of Orchard and I can't reproduce the issue. My filters get called only once, despite the fact that the event is called twice.

NathanaelJones wrote Jul 9, 2013 at 6:21 PM

The filters don't necessarily get called twice; but the response is duplicated.

sebastienros wrote Jul 9, 2013 at 8:30 PM

I can't get it duplicated either, though I have seen it on several customers so I don't question the fact that it happens, just the repro is not working for me. I will try again.

urbanit wrote Jul 10, 2013 at 7:11 AM

Seems to be corrected with the new OuptuCache! Thanx @SebastienRos