Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 647
George2 Avatar asked Nov 21 '25 01:11

George2


1 Answers

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

like image 50
marc_s Avatar answered Nov 23 '25 15:11

marc_s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!