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


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01