【问题标题】:fire module before the output cache module fires在输出缓存模块触发之前触发模块
【发布时间】:2013-09-16 08:54:38
【问题描述】:

我正在使用 asp.net mvc 输出缓存,但遇到了问题。

我正在使用构建自定义字符串的客户实现覆盖全局 asax 中的 GetVaryByCustomString 方法。在此字符串上构建是基于插入到另一个 httpmodule 中的 httpcontext 的数据。

我遇到的问题是 OutputCacheModule 在将值放入 httpcontext 之前被触发 - 这是在另一个 httpmodule 中完成的。

有什么方法可以在 outputcache 模块执行之前触发不同的 httpmodule?

或者我的情况还有其他解决方法吗?

【问题讨论】:

  • 对模块重新排序怎么样?

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


【解决方案1】:

尝试按照 .net 管道 (http://msdn.microsoft.com/en-us/library/ff649096.aspx) 执行事件的顺序对事件进行排序。

例如,您可以使用 BeginRequest 事件,即第一个要引发的事件:

public class MyModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.BeginRequest += context_BeginRequest;            
    }

    void context_BeginRequest(object sender, EventArgs e)
    {
        var application = (HttpApplication)sender;
        var context = application.Context;

        // do something
    }

    public void Dispose()
    {
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 2021-09-30
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    相关资源
    最近更新 更多