我已经在HTTP模块上声明了一个事件,因此它将对True/False值进行轮询订阅者,以确定是否应该继续调整其调整HTTP响应的任务。如果只有一个订户答案是正确的,那么它将运行其逻辑。

这有意义吗?
我没有看到潜在的陷阱吗?

public class ResponseTweaker : IHttpModule {

    // to be a list of subscribers 
    List<Func<HttpApplication, bool>> listRespondants = new List<Func<HttpApplication, bool>>();

    // event that stores its subscribers in a collection
    public event Func<HttpApplication, bool> RequestConfirmation {
        add {
            listRespondants.Add(value);
        }
        remove {
            listRespondants.Remove(value);
        }
    }

    public void Init(HttpApplication context) {
        if (OnGetAnswer(context)) // poll subscribers ...
            // Conditionally Run Module logic to tweak Response ... 
    }

    /* Method that polls subscribers and returns 'true'
     *  if only one of them answers yes.
     */
    bool OnGetAnswer(HttpApplication app) {
        foreach (var respondant in listRespondants)
            if (respondant(app))
                return true;
        return false;
    }

    // etc...
}
有帮助吗?

解决方案

我认为这不是一个好主意。问题的数量将取决于...

  1. LISTRESPONDENS将植根,因此将具有应用寿命。如果有大量项目被添加,则内存足迹将不断增加。因此,它宁愿归结为此列表中的项目数量。

以下可以是表演止动...

  1. IISRESET或应用程序域回收将从您的应用程序中删除所有这些信息。您打算如何将项目带回此列表中?数据库?

  2. 如果您有一个网络农场怎么办。当您尝试扩展时,此应用程序将无法正常工作。原因是...即使您在网络农场中的所有服务器上都加载了相同的模块,但工作过程中的数据是本地的。因此,除非您从某些数据库加载它,否则LISTRESPONDERS在所有服务器中都会有所不同。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top