【问题标题】:Logging raw and compressed HTTP responses in ASP.NET & IIS7在 ASP.NET 和 IIS7 中记录原始和压缩的 HTTP 响应
【发布时间】:2012-06-18 13:59:22
【问题描述】:

按照this question 的思路,我想创建一个 HttpModule 来为我们记录一些自定义的请求和响应。使用该问题的最流行答案中的代码,我已经启动并运行了一个确实有效的 HttpModule:

class PortalTrafficModule : IHttpModule
{
    public void Dispose()
    {
        // Do Nothing
    }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
        context.EndRequest += new EventHandler(context_EndRequest);
    }

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

        // Create and attach the OutputFilterStream to the Response and store it for later retrieval.
        OutputFilterStream filter = new OutputFilterStream(context.Response.Filter);
        context.Response.Filter = filter;
        context.Items.Add("OutputFilter", filter);

        // TODO: If required the request headers and content could be recorded here
    }

    private void context_EndRequest(object sender, EventArgs e)
    {
        HttpContext context = ((HttpApplication)sender).Context;
        OutputFilterStream filter = context.Items["OutputFilter"] as OutputFilterStream;

        if (filter != null)
        {
            // TODO: Log here - for now just debug.
            Debug.WriteLine("{0},{1},{2}",
                context.Response.Status,
                context.Request.Path,
                filter.ReadStream().Length);
        }
    }
}

(注意代码中引用的OutputFilterStream类在引用的question中)。

但是,响应似乎缺少我在 Fiddler 中看到的一些 HTTP 标头(例如“日期”),更重要的是,当我打开压缩时,我正在记录的响应没有被压缩,而我在 Fiddler 中看到的是。

所以我的问题 - 是否可以记录压缩内容,或者这是否发生在我的模块无法连接到的后续步骤中?

作为记录,我也尝试过处理 PreSendRequestContent 事件,但响应仍未压缩。

【问题讨论】:

  • 你解决过这个问题吗?
  • 不,不怕,不久之后我就放弃了我正在做的事情!祝你好运!

标签: asp.net logging iis-7 compression ihttpmodule


【解决方案1】:

您好,虽然我无法直接回答您的问题,但我过去曾做过类似的事情,并且发现以下资源非常有帮助和启发性。最后,通过在 web config 中配置 System.Diagnostics 节点并创建流量跟踪日志,我设法实现了我需要的原始 soap 标头。我了解您的需求可能比这更细化,但我相信此资源可能仍有帮助。

http://msdn.microsoft.com/en-us/library/ms731859

特别感兴趣的可能是上面的消息日志配置和查看消息日志链接。

【讨论】:

    猜你喜欢
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 2011-05-23
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多