我在 web.config 中启用了 trace pageoutput="true",我喜欢它提供的在页面底部查看所有这些内容的简单方法。
我想从我的 httphandler 输出底部的跟踪中获得相同的输出。有没有办法通过遵循此代码的代码转储相同的跟踪信息:
public class UploadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
我特别想看看 Forms 和 QueryString 集合,但所有这些都是“Hello World”。
-- 编辑更新 2009 年 7 月 25 日:
public class UploadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
object htw = new System.Web.UI.Html32TextWriter(context.Response.Output);
{
typeof(TraceContext)
.GetMethod("Render", System.Reflection.BindingFlags.NonPublic)
.Invoke(HttpContext.Current.Trace, new object[] { htw });
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
对于如何最轻松地获得表单和查询字符串集合的格式化转储(如 pageOutput 跟踪),我也愿意接受任何其他想法。