【问题标题】:control order of firing asp.net mvc httpmodules触发asp.net mvc httpmodules的控制顺序
【发布时间】:2013-09-16 18:32:14
【问题描述】:

我在我的 .net 应用程序中使用 asp.net mvc 输出缓存,但想控制它何时被触发。我有另一个自定义 http 模块,我需要在输出缓存模块触发之前触发它。我在 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>

问题是它仍然无法控制模块触发的顺序。输出缓存模块仍然在自定义模块之前触发。有什么办法可以解决这个问题?

我尝试创建 OutputCacheModule 的自定义实现,但由于它是一个密封类,我无法做到。

有什么帮助吗?

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 httpmodule outputcache


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-11-06
      • 2015-11-02
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-01
      • 2019-04-15
      相关资源
      最近更新 更多