TraceHandler.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // System.Web.Handlers.TraceHandler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. // Jackson Harper ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc (http://www.ximian.com)
  9. // (C) 2004 Novell, Inc (http://www.novell.com)
  10. //
  11. using System.Web;
  12. using System.Web.Util;
  13. using System.Web.UI;
  14. using System.Web.UI.WebControls;
  15. namespace System.Web.Handlers
  16. {
  17. public class TraceHandler : IHttpHandler
  18. {
  19. void IHttpHandler.ProcessRequest (HttpContext context)
  20. {
  21. TraceManager manager = HttpRuntime.TraceManager;
  22. HtmlTextWriter output = new HtmlTextWriter (context.Response.Output);
  23. if (context.Request.QueryString ["clear"] != null)
  24. manager.Clear ();
  25. string id_str = context.Request.QueryString ["id"];
  26. int id = -1;
  27. if (id_str != null)
  28. id = Int32.Parse (id_str);
  29. if (id > 0 && id <= manager.ItemCount) {
  30. RenderItem (manager, output, id);
  31. } else {
  32. string dir = context.Server.MapPath (UrlUtils.GetDirectory (context.Request.FilePath));
  33. RenderMenu (manager, output, dir);
  34. }
  35. }
  36. bool IHttpHandler.IsReusable
  37. {
  38. get {
  39. return false;
  40. }
  41. }
  42. private void RenderMenu (TraceManager manager, HtmlTextWriter output, string dir)
  43. {
  44. output.RenderBeginTag (HtmlTextWriterTag.Html);
  45. output.RenderBeginTag (HtmlTextWriterTag.Head);
  46. TraceData.RenderStyleSheet (output);
  47. output.RenderEndTag ();
  48. RenderHeader (output, dir);
  49. output.RenderBeginTag (HtmlTextWriterTag.Body);
  50. output.AddAttribute ("class", "tracecontent");
  51. output.RenderBeginTag (HtmlTextWriterTag.Span);
  52. Table table = TraceData.CreateTable ();
  53. table.Rows.Add (TraceData.AltRow ("Requests to the Application"));
  54. table.Rows.Add (TraceData.SubHeadRow ("No", "Time of Request",
  55. "File", "Status Code", "Verb", "&nbsp;"));
  56. if (manager.TraceData != null) {
  57. for (int i=0; i<manager.ItemCount; i++) {
  58. int item = i + 1;
  59. TraceData d = manager.TraceData [i];
  60. TraceData.RenderAltRow (table, i, item.ToString (), d.RequestTime.ToString (),
  61. d.RequestPath, d.StatusCode.ToString (), d.RequestType,
  62. "<a href=\"Trace.axd?id=" + item + "\" class=\"tinylink\">" +
  63. "<b><nobr>View Details</a>");
  64. }
  65. table.RenderControl (output);
  66. }
  67. output.RenderEndTag ();
  68. output.RenderEndTag ();
  69. output.RenderEndTag ();
  70. }
  71. private void RenderHeader (HtmlTextWriter output, string dir)
  72. {
  73. Table table = TraceData.CreateTable ();
  74. TableRow row1 = new TableRow ();
  75. TableRow row2 = new TableRow ();
  76. TableCell cell1 = new TableCell ();
  77. TableCell cell2 = new TableCell ();
  78. TableCell cell3 = new TableCell ();
  79. TableCell cell4 = new TableCell ();
  80. cell1.Text = "<h1>Application Trace</h1>";
  81. cell2.Text = "[ <a href=\"Trace.axd?clear=1\" class=\"link\">clear current trace</a> ]";
  82. cell2.HorizontalAlign = HorizontalAlign.Right;
  83. cell2.VerticalAlign = VerticalAlign.Bottom;
  84. row1.Cells.Add (cell1);
  85. row1.Cells.Add (cell2);
  86. cell3.Text = "<h2><h2><p>"; // ummm, WTF?
  87. cell4.Text = "<b>Physical Directory:</b>" + dir;
  88. row2.Cells.Add (cell3);
  89. row2.Cells.Add (cell4);
  90. table.Rows.Add (row1);
  91. table.Rows.Add (row2);
  92. table.RenderControl (output);
  93. }
  94. private void RenderItem (TraceManager manager, HtmlTextWriter output, int item)
  95. {
  96. manager.TraceData [item - 1].Render (output);
  97. }
  98. }
  99. }