Logging raw and compressed HTTP responses in ASP.NET amp; IIS7(在 ASP.NET amp; 中记录原始和压缩的 HTTP 响应IIS7)
问题描述
按照这个问题 我想创建一个 HttpModule 来为我们记录一些自定义的请求和响应.使用该问题最流行的答案中的代码,我已经启动并运行了一个确实有效的 HttpModule:
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);
}
}
}
(注意代码中引用的OutputFilterStream类在引用的问题).
但是,响应似乎缺少我在 Fiddler 中看到的一些 HTTP 标头(例如日期"),更重要的是,当我打开压缩时,我正在记录的响应没有被压缩,而我在 Fiddler 中看到的是.
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.
所以我的问题 - 是否可以记录压缩内容,或者这是否发生在我的模块无法连接的后续步骤中?
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 事件,但响应仍未压缩.
For the record, I've also tried handling the PreSendRequestContent event and the response is still uncompressed.
推荐答案
您好,虽然我无法直接回答您的问题,但我过去曾做过类似的事情,并且发现以下资源非常有帮助和启发.最后,通过在 web config 中配置 System.Diagnostics 节点并创建流量跟踪日志,我设法实现了我需要的原始 soap 标头.我了解您的需求可能比这更细化,但我相信此资源可能仍有帮助.
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.
这篇关于在 ASP.NET & 中记录原始和压缩的 HTTP 响应IIS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 ASP.NET & 中记录原始和压缩的 HTTP 响应IIS7
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01