记录原始和COM pressed HTTP在ASP.NET和放大器的响应; IIS7 [英] Logging raw and compressed HTTP responses in ASP.NET & IIS7

查看:169
本文介绍了记录原始和COM pressed HTTP在ASP.NET和放大器的响应; IIS7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

沿this问题我想创建一个HTTP模块,将尽我们的请求和响应的一些自定义日志记录。在这个问题最普遍的回答使用code我有一个HTTP模块运行起来这的确不工作:

Along the lines of this question I want to create a HttpModule that will do some custom logging of requests and responses for us. Using the code in the most popular answer for that question I've got a HttpModule up and running which does indeed work:

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);
        }
    }
}

(注意在code所指的OutputFilterStream类是在引用的<一href=\"http://stackoverflow.com/questions/1038466/logging-raw-http-request-response-in-asp-net-mvc-iis7\">question).

不过,反应似乎缺少一些HTTP头,我在看到提琴手(如日),更重要的是,当我打开COM pression我记录的反应都没有COM pressed而我在看到提琴手是什么。

However, the responses seem to be missing some HTTP headers that I see in Fiddler (like "Date") and more importantly, when I turn on compression the responses I'm logging aren't compressed whereas what I see in Fiddler is.

所以我的问题 - 是否有可能记录COM pressed内容或会出现这种情况在后续步骤中我的模块不能钩住

So my question - is it possible to log the compressed content or is this happening in a subsequent step my module can't hook in to?

有关记录,我也试着处理的 preSendRequestContent 的事件和反应还是uncom pressed。

For the record, I've also tried handling the PreSendRequestContent event and the response is still uncompressed.

推荐答案

虽然我不能回答你的问题,直接我不得不事业做类似的事情在过去,发现下面的资源非常有帮助和启发。最后,我设法acheive我需要的东西为原料的SOAP头通过配置web配置中的节点System.Diagnostics程序,创造流量的跟踪日志。据我所知,您的需求可能会更精细的比,但是我相信这个资源可能依然帮助。

Hi although I cannot answer your questions directly I have had cause to do similar things in the past and have found the following resource extremely helpful and enlightening. In the end I managed to acheive what I needed for raw soap headers by configuring the System.Diagnostics node within web config and create a trace log of traffic. I understand that your needs may be more granular than that however I believe this resource may still help.

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

特别感兴趣的可以是该消息日志配置和观看信息记录来自上述一个链接。

Of particular interest may be the message log configuration and viewing message logs links from the one above.

这篇关于记录原始和COM pressed HTTP在ASP.NET和放大器的响应; IIS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆