views:

935

answers:

1

Hello everyone,

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

+2  A: 

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

marc_s
I met with not supported exception. I have posted my code in edit 1 section of my original question, any ideas what is wrong?
George2
Does the error message mean I must deploy into IIS? I have tried the same code works in IIS. Please help to confirm.
George2
If it's an ASP.NET app as you say, it **IS** hosted in IIS! Is it hosted on IIS7 ?? In that case, you need to make sure your virtual directory uses the "Classic ASP.NET mode" (at least in my experience)
marc_s
Hi Marc, 1. I do not host it normally in IIS, I just press F5 to debug it and when stable, I will deploy to IIS 7. If press F5, the application should run in VSTS2008 built-in ASP.Net development server other than IIS. Do you think my problem is caused by VSTS2008 built-in ASP.Net development server does not support OnPreRender method? Any other comments? 2. Where to set "Classic ASP.NET mode"? In VSTS 2008 or in IIS 7?
George2
Hi Marc, I found how to set Classic or Integrated mode in IIS 7, but cannot find how to set in VSTS 2008 built-in ASP.Net development server, any ideas?
George2
Well, it seems trying to dump out the Response headers while creating the response on your page is **only** supported on IIS7 with the integrated pipeline mode - no workaround available for the VS built-in webserver Cassini :-(
marc_s