1

我正在为一个 .net 2.0 应用程序设置一些健康监控。

我希望能够获取原始网络请求对象。我希望能够检查通过发送的标头以及任何发布数据(如果可能)。

我目前有一个从 WebEventProvider 继承的事件提供程序,但这仅包括 HttpWebResponse 数据,而不包括请求。

我该怎么办?

4

1 回答 1

1

您打算仅对您的应用程序或 IIS 中的所有应用程序进行健康监控吗?

仅对于您自己的应用程序,您可以创建一个类并从 IHttpModule 派生,并且在其 Init 方法中您可以创建事件通知,甚至可以监视请求和任何其他状态。

public class MyMonitor : IHttpModule
{

        public void Init(HttpApplication context)
        {
            // you can watch any of such events and respond accordingly
            context.BeginRequest += new EventHandler(context_BeginRequest);
            context.PostUpdateRequestCache += 
               new EventHandler(context_PostUpdateRequestCache);
            context.Error += new EventHandler(context_Error);
        }
        .....
}

您可以在 web.config 中添加以下行

<httpModules>
    <add name="MyMonitor" type="Namespace.MyMonitor"/>
</httpModules>
于 2009-06-26T12:21:33.333 回答