Вопрос

I am using asp.net mvc output caching in my .net application but want to control when it gets fired. I have another custom http module that I need to fire prior to the output cache module firing. I made following change in web.config

  <modules runAllManagedModulesForAllRequests="false">
        <remove name="OutputCache" />
        <add name="MyCustomModule" type="Namespace.MyCustomModule" preCondition="managedHandler" />
        <add name="OutputCache2" type="System.Web.Caching.OutputCacheModule"/>
        <remove name="PassportAuthentication" />
        <remove name="Profile" />
        <remove name="AnonymousIdentification" />
        <remove name="FileAuthorization" />
        <remove name="Session" />
        <remove name="WindowsAuthentication" />
        <remove name="UrlAuthorization" />
    </modules>

Problem is its still not controlling the order the modules fire. Output cache module still fires before custom module. Any way to manage this?

I tried creating a custom implementation of the OutputCacheModule but as its a sealed class I was not able to.

Any help?

Это было полезно?

Решение

I would recommend using a custom HttpModule that implements the IHttpModule interface and subscribing to the PostAuthorizeRequest event in the Init method of your custom HttpModule this event fires right before the caching events in the MVC application life cycle. You will need to add your custom module to the web.config no modules need to be removed or reordered since you are subscribing to the events fired by the HttpApplication class in the module which controls the pipeline. You could also implement this without the custom module in the Global.asax

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top