George2
George2

Reputation: 45801

how to dump response headers in ASP.Net

I am using VSTS 2008 + C# + .Net 3.5 to develop ASP.Net. I want to dump all response headers returned to client for a specific aspx file. Any ideas how to do this easily?

I know how to use Response.Headers collection, but my confusion is where to enumerate to get the accurate response header? For example, if I enumerate in Page_Load, not all response headers could be enumerated, but if I enumerate after Response.Close, exception will be thrown.

Any advice?

EDIT1: Meeting with the following exception when using OnPreRender in VSTS 2008 debug mode (i.e. pressing F5 to debug)

{"This operation requires IIS integrated pipeline mode."}

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            using (StreamWriter writer = new StreamWriter("dump123.txt", true))
            {
                writer.WriteLine(DateTime.UtcNow + " Response headers");
                foreach (string item in HttpContext.Current.Response.Headers.Keys)
                {
                    writer.WriteLine(item + " : " + HttpContext.Current.Response.Headers[item]);
                }
            }

        }

thanks in advance, George

Upvotes: 3

Views: 4263

Answers (2)

Sudhanshu Mishra
Sudhanshu Mishra

Reputation: 6733

[This may be old for the original question, but adding this answer for the benefit of newbees who might land here]

Change your web project's properties to use the local IIS for debugging as follows:

  1. Browse to Project properties (right click on project node in solution explorer ->properties OR with project node selected, press ALT+ENTER)
  2. Select the "Build" tab
  3. In the servers section, Select the radio button "Use Local IIS Server" Setup a virtual directory in your local IIS and point to that URL in the settings here

A detailed tutorial on the setup can be found HERE

Now when you hit F5, local IIS would be used for debugging and you would not get the platform not supported exception/complain about integrated pipeline mode required.

Upvotes: 0

marc_s
marc_s

Reputation: 755321

What about OnPreRender?? That's just before the page gets rendered, and after all hte postback processing has taken place. Everything should be in place by that time.

Marc

Upvotes: 3

Related Questions