Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know how I could get IIS to log POST data or the entire HTTP request?

share|improve this question

The IIS logs only record querystring and header information without any POST data.

If you're using IIS7, you can enabled Failed Request Tracing for status code 200. That will record all of the data and you can select which type of data to include.

In either IIS6 or 7, you can use Application_BeginRequest in global.asax and create your own logging of POST data.

Or, in IIS7, you can write a HTTP Module with your own custom logging.

share|improve this answer
+1 - I like your answer far, far better than my own. I clearly need to read up on failed request tracing, since I obviously haven't used IIS7 as much as I should. – Evan Anderson Dec 4 '09 at 11:52
How can you "select which type of data to include"? – Pavel Chuchuva Aug 23 '12 at 1:31
The last step of the wizard when creating a FRT rule allows you to select which data to include. It defaults to including everything. – Scott Forsyth - MVP Aug 24 '12 at 19:24
I was looking for something for IIS6 but came across this link which shows advanced logging is an add-on option for IIS7.… – andyknas Mar 30 at 19:52

In managed code you can use the Response.AppendToLog method.  This method will append data to the cs-uri-stem field -- the total length is up to 4100 characters (undocumented).  If you exceed that limit, then the value that would have been logged is replaced with "..."

For instance, adding something like this to your Global.asax file should do the trick (C#):

void Application_EndRequest(Object Sender, EventArgs e)
    if( "POST" == Request.HttpMethod )
        byte[] bytes    = Request.BinaryRead(Request.TotalBytes);
        string s    = Encoding.UTF8.GetString(bytes);
        if (!String.IsNullOrEmpty(s))
            int QueryStringLength = 0;
            if (0 < Request.QueryString.Count)
                QueryStringLength = Request.ServerVariables["QUERY_STRING"].Length;
                Response.AppendToLog( "&" );

            if (4100 > ( QueryStringLength + s.Length ) )
                // append only the first 4090 the limit is a total of 4100 char.
                Response.AppendToLog(s.Substring(0, ( 4090 - QueryStringLength )));
                // indicate buffer exceeded
                // TODO: if s.Length >; 4000 then log to separate file
share|improve this answer
As of this comment, the limit is not 4100, it's 4KB which is 4096. So this code needs to be modified slightly to log POST data >4KB correctly. – Steven V Jan 29 '14 at 20:42
I had to add HttpContext.Current.Request.InputStream.Position = 0; before request.BinaryRead, otherwise it would return empty array – alex440 May 14 '14 at 9:40

While I appreciate that this is an old question, I found this code gave me exactly what I needed, a text file with the complete request headers and the response, put it into your global.asax.cs:

protected void Application_BeginRequest(Object Sender, EventArgs e)
    string uniqueid = DateTime.Now.Ticks.ToString();
    string logfile = String.Format("C:\\path\\to\\folder\\requests\\{0}.txt", uniqueid);
    Request.SaveAs(logfile, true);

This will create a text file for each and every request (including images) so be careful where you use it. I only used it to log specific post requests.

share|improve this answer

Try enabling the following in your IIS log settings:

Method (cs-method)

URI Stem (cs-uri-stem)

URI Query (cs-uri-query)

share|improve this answer
I've tried, haven't helped... :( – Budda Oct 20 '10 at 21:21
Those settings will not include POST data – rob May 14 '14 at 10:03

protected by HopelessN00b Feb 18 '15 at 11:54

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?