2

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

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

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

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

或者是否有针对我的情况的另一种解决方法。

4

1 回答 1

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()
    {
    }
}
于 2014-09-23T21:33:46.663 回答