1

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?

4

1 回答 1

1

我建议使用实现 IHttpModule 接口的自定义 HttpModule 并在自定义 HttpModule 的 Init 方法中订阅 PostAuthorizeRequest 事件,此事件在 MVC 应用程序生命周期中的缓存事件之前触发。您需要将自定义模块添加到 web.config 不需要删除或重新排序模块,因为您订阅了由控制管道的模块中的 HttpApplication 类触发的事件。您也可以在没有 Global.asax 中的自定义模块的情况下实现这一点

于 2014-02-20T08:48:23.587 回答