7

I run IIS 5 on my dev machine. I have an asp.net 3.5 web service running on it which I'm calling from a different web app running on the same server. My service is returning an error 500 Internal Server error and I'm troubleshooting it. My request is being sent via a System.Net.HttpWebRequest object and it looks valid from the client's perspective.

I'd like to see the raw incoming HTTP request from the server's perspective. Since the service is being called on loopback, I can't use Wireshark to see it.

IIS Logging shows me the request header but not the post content.

Any suggestions on how I could see the full raw incoming HTTP request in IIS?

Thanks

5 Answers 5

3

I would think you want to add an HTTPModule for logging. Here's a pretty good article on ASP.NET modules and handlers:

That way, when you want to disable logging, you can just remove/comment it from your web.config file.

Sign up to request clarification or add additional context in comments.

Comments

3

Have you tried using Fiddler? Just use your machine name instead of localhost.

2 Comments

Fiddler works if you're querying from a browser. Webservice calls from within my own apps won't work.
@Mr Greieves, it takes a little bit of extra work, but you can manually configure the proxy settings for your webservice calls.
2

I'm able to log request/response with many data (request body included for http post etc...), all http verbs included (ex: get, post) using IIS Failed Request Tracing

enter image description here

The request does not necessarily needs to fail to be logged as you can specify there any http status like 200, 401 etc or just all (enter 100-999).

You can also just log requests with a specific URL

enter image description here

I'll later implement a custom http module for more control.

Thanks

Comments

0

Your best bet is to run each of your web apps on a different port, and then use something like Fiddler to create a proxy for the port you want to watch. This will monitor all traffic to and from your specific application.

Comments

0

Here is code of custom HTTP module we use to log HTTP POST request data.

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

    }
}

Do not forget to register it in web.config of you application.

Use system.WebServer section for IIS Integrated Model

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

Use system.web section for IIS Classic Model

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

IIS log Before applying module:

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

IIS log After applying module:

::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"}},

Full article:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.