Code snippet to write the httpresponse and httprequest object to a text file

I need to troubleshoot a issue with session getting abandoned.  In the following c# code, I need to write a the detailed httprequest and httpresponse in a text file to analyze further. One of the reason why I want to do this is to identify from which procedure the request was made which is causing the session to abandon. Sample code is given below. Any help will be highly appreciated.

  void Application_PostRequestHandlerExecute(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            HttpRequest req = app.Request;
            HttpResponse resp = app.Response;

            ///Code to capture the httprequest and httpresponse.

             if (!ValidateRequest(req, resp))
            {
                FormsAuthentication.SignOut();
                Session.Abandon();
                resp.Redirect(loginVPath, true);
            }
            }
        }
Star79Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
The object cannot be written to file because these classes are not serializable. In fact M$ make them obsolete as shown below:
- httpwebrequest
- httpwebresponse

Options:
O1. Use Fiddler to examine the request.
O2. Add Trace.WriteLine to ValidateRequest method on every condition that return false and log any relevant condition values.
O3. Create your own custom serialization, but this is a big task in itself and not all properties of these objects are serializable, thus you are going to need to identify which properties do require manual coding.
My recommendation will be to use Options 1 and 2 first.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.