how to dump response headers in ASP.Net

柔情痞子 提交于 2019-12-06 07:05:34

问题


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


回答1:


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




回答2:


[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.



来源:https://stackoverflow.com/questions/1184013/how-to-dump-response-headers-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!