C#C
C#4mo ago
TangoBee

How to capture request body in IIS managed module

Hi,
I'm trying to create an IIS server module that can capture all the incoming and outgoing traffic and send it to my backend server.
So, when I try to add the code below in my module and try to capture the request body, all the requests that contain a payload time out after 60 seconds. However, all the other requests that don't contain any payload work fine. If I remove the code below, then everything works fine, but I won't be able to capture the request body.


code to capture request body:
                using (var reader = new StreamReader(request.GetBufferedInputStream(), request.ContentEncoding))
                {
                    string requestBody = reader.ReadToEnd();
                    HttpContext.Current.Items["RequestPayload"] = requestBody;
                }



Full code: https://pastecord.com/beqynygimu.cs
Was this page helpful?