2 // System.Web.Handlers.TraceHandler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Jackson Harper (jackson@ximian.com)
8 // (C) 2002 Ximian, Inc (http://www.ximian.com)
9 // (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
36 using System.Web.Util;
38 using System.Web.UI.WebControls;
40 namespace System.Web.Handlers
42 public class TraceHandler : IHttpHandler
44 void IHttpHandler.ProcessRequest (HttpContext context)
46 TraceManager manager = HttpRuntime.TraceManager;
48 if (manager.LocalOnly && !context.Request.IsLocal) {
49 // Need to figure out the error message that goes here
50 // but I only have cassini for testing
54 HtmlTextWriter output = new HtmlTextWriter (context.Response.Output);
56 if (context.Request.QueryString ["clear"] != null)
59 string id_str = context.Request.QueryString ["id"];
62 id = Int32.Parse (id_str);
64 if (id > 0 && id <= manager.ItemCount) {
65 RenderItem (manager, output, id);
67 string dir = context.Server.MapPath (UrlUtils.GetDirectory (context.Request.FilePath));
68 RenderMenu (manager, output, dir);
73 bool IHttpHandler.IsReusable
80 private void RenderMenu (TraceManager manager, HtmlTextWriter output, string dir)
83 output.RenderBeginTag (HtmlTextWriterTag.Html);
85 output.RenderBeginTag (HtmlTextWriterTag.Head);
86 TraceData.RenderStyleSheet (output);
87 output.RenderEndTag ();
89 RenderHeader (output, dir);
91 output.RenderBeginTag (HtmlTextWriterTag.Body);
92 output.AddAttribute ("class", "tracecontent");
93 output.RenderBeginTag (HtmlTextWriterTag.Span);
95 Table table = TraceData.CreateTable ();
97 table.Rows.Add (TraceData.AltRow ("Requests to the Application"));
98 table.Rows.Add (TraceData.SubHeadRow ("No", "Time of Request",
99 "File", "Status Code", "Verb", " "));
101 if (manager.TraceData != null) {
102 for (int i=0; i<manager.ItemCount; i++) {
104 TraceData d = manager.TraceData [i];
105 TraceData.RenderAltRow (table, i, item.ToString (), d.RequestTime.ToString (),
106 d.RequestPath, d.StatusCode.ToString (), d.RequestType,
107 "<a href=\"Trace.axd?id=" + item + "\" class=\"tinylink\">" +
108 "<b><nobr>View Details</a>");
110 table.RenderControl (output);
113 output.RenderEndTag ();
114 output.RenderEndTag ();
116 output.RenderEndTag ();
119 private void RenderHeader (HtmlTextWriter output, string dir)
121 Table table = TraceData.CreateTable ();
122 TableRow row1 = new TableRow ();
123 TableRow row2 = new TableRow ();
124 TableCell cell1 = new TableCell ();
125 TableCell cell2 = new TableCell ();
126 TableCell cell3 = new TableCell ();
127 TableCell cell4 = new TableCell ();
129 cell1.Text = "<h1>Application Trace</h1>";
130 cell2.Text = "[ <a href=\"Trace.axd?clear=1\" class=\"link\">clear current trace</a> ]";
132 cell2.HorizontalAlign = HorizontalAlign.Right;
133 cell2.VerticalAlign = VerticalAlign.Bottom;
135 row1.Cells.Add (cell1);
136 row1.Cells.Add (cell2);
138 cell3.Text = "<h2><h2><p>"; // ummm, WTF?
139 cell4.Text = "<b>Physical Directory:</b>" + dir;
141 row2.Cells.Add (cell3);
142 row2.Cells.Add (cell4);
144 table.Rows.Add (row1);
145 table.Rows.Add (row2);
147 table.RenderControl (output);
150 private void RenderItem (TraceManager manager, HtmlTextWriter output, int item)
152 manager.TraceData [item - 1].Render (output);
155 [MonoTODO ("Appears in class status, but...")]
156 protected void ShowDetails (DataSet data)
160 [MonoTODO ("Appears in class status, but...")]
161 protected void ShowRequests (ArrayList list)