如何记录进入IIS的HTTP请求

时间:2009-04-13 16:19:38

标签: http iis

我在开发机器上运行IIS 5。我有一个运行在其上的asp.net 3.5 Web服务,我从同一服务器上运行的另一个Web应用程序调用。我的服务返回错误500内部服务器错误,我正在对其进行故障排除。我的请求是通过System.Net.HttpWebReques t对象发送的,从客户的角度来看它看起来很有效。

我想从服务器的角度看待原始的传入HTTP请求。由于服务是在环回上调用的,我不能使用Wireshark来查看它。

IIS Logging向我显示请求标题,但不显示帖子内容。

有关如何在IIS中看到完整的原始传入HTTP请求的建议吗?

由于

4 个答案:

答案 0 :(得分:4)

您是否尝试过使用Fiddler?只需使用您的机器名称而不是localhost。

答案 1 :(得分:3)

我认为您想要添加HTTPModule以进行日志记录。 Here's关于ASP.NET模块和处理程序的一篇非常好的文章:

这样,当您想要禁用日志记录时,您可以从web.config文件中删除/注释它。

答案 2 :(得分:0)

最好的办法是在不同的端口上运行每个网络应用,然后使用类似Fiddler的内容为您要观看的端口创建代理。这将监控进出特定应用程序的所有流量。

答案 3 :(得分:0)

以下是我们用于记录HTTP POST请求数据的自定义HTTP模块的代码。

using System;
using System.Web;

namespace MySolution.HttpModules
{
    public class HttpPOSTLogger : IHttpModule
    {

        public void Dispose()
        {
        }

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

        private void context_BeginRequest(object sender, EventArgs e)
        {
            if (sender != null && sender is HttpApplication)
            {
                var request = (sender as HttpApplication).Request;
                var response = (sender as HttpApplication).Response;

                if (request != null && response != null && request.HttpMethod.ToUpper() == "POST")
                {
                    var body = HttpUtility.UrlDecode(request.Form.ToString());
                    if (!string.IsNullOrWhiteSpace(body))
                        response.AppendToLog(body);
                }
            }
        }

    }
}

不要忘记在你的应用程序的web.config中注册它。

对IIS集成模型使用system.WebServer部分

<system.webServer>
    <modules>
      <add name="HttpPOSTLogger" type="MySolution.HttpModules.HttpPOSTLogger, MySolution.HttpModules" />
    </modules>
</system.webServer>

对IIS经典模型使用system.web部分

<system.web>
    <httpModules>
        <add name="HttpPOSTLogger" type="MySolution.HttpModules.HttpPOSTLogger, MySolution.HttpModules"/>
    </httpModules>
</system.web>

IIS日志在应用模块之前:

::1, -, 10/31/2017, 10:53:20, W3SVC1, machine-name, ::1, 5, 681, 662, 200, 0, POST, /MySolution/MyService.svc/MyMethod, -,

IIS日志应用模块后:

::1, -, 10/31/2017, 10:53:20, W3SVC1, machine-name, ::1, 5, 681, 662, 200, 0, POST, /MySolution/MyService.svc/MyMethod, {"model":{"Platform":"Mobile","EntityID":"420003"}},

全文:

https://www.codeproject.com/Tips/1213108/HttpModule-for-logging-HTTP-POST-data-in-IIS-Log

相关问题