(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / System.Web.Handlers / TraceHandler.cs
blob23e35288f80454f58da4a4e07f96147cc22946cd
1 //
2 // System.Web.Handlers.TraceHandler
3 //
4 // Authors:
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Jackson Harper (jackson@ximian.com)
7 //
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:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
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;
34 using System.Data;
35 using System.Web;
36 using System.Web.Util;
37 using System.Web.UI;
38 using System.Web.UI.WebControls;
40 namespace System.Web.Handlers
42 #if NET_2_0
43 [Serializable]
44 #endif
45 class TraceNotAvailableException : HttpException
47 bool notLocal;
49 public TraceNotAvailableException (bool notLocal) :
50 base (notLocal ? 403 : 500, "Trace Error")
52 this.notLocal = notLocal;
55 internal override string Description {
56 get {
57 if (notLocal)
58 return "Trace is not enabled for remote clients.";
60 return "Trace.axd is not enabled in the configuration file for this application.";
65 public class TraceHandler : IHttpHandler
67 void IHttpHandler.ProcessRequest (HttpContext context)
69 TraceManager manager = HttpRuntime.TraceManager;
71 if (!manager.Enabled || manager.LocalOnly && !context.Request.IsLocal)
72 throw new TraceNotAvailableException (manager.Enabled);
74 HtmlTextWriter output = new HtmlTextWriter (context.Response.Output);
76 if (context.Request.QueryString ["clear"] != null)
77 manager.Clear ();
79 string id_str = context.Request.QueryString ["id"];
80 int id = -1;
81 if (id_str != null)
82 id = Int32.Parse (id_str);
84 if (id > 0 && id <= manager.ItemCount) {
85 RenderItem (manager, output, id);
86 } else {
87 string dir = context.Server.MapPath (UrlUtils.GetDirectory (context.Request.FilePath));
88 RenderMenu (manager, output, dir);
93 bool IHttpHandler.IsReusable
95 get {
96 return false;
100 private void RenderMenu (TraceManager manager, HtmlTextWriter output, string dir)
103 output.RenderBeginTag (HtmlTextWriterTag.Html);
105 output.RenderBeginTag (HtmlTextWriterTag.Head);
106 TraceData.RenderStyleSheet (output);
107 output.RenderEndTag ();
109 RenderHeader (output, dir);
111 output.RenderBeginTag (HtmlTextWriterTag.Body);
112 output.AddAttribute ("class", "tracecontent");
113 output.RenderBeginTag (HtmlTextWriterTag.Span);
115 Table table = TraceData.CreateTable ();
117 table.Rows.Add (TraceData.AltRow ("Requests to the Application"));
118 table.Rows.Add (TraceData.SubHeadRow ("No", "Time of Request",
119 "File", "Status Code", "Verb", "&nbsp;"));
121 if (manager.TraceData != null) {
122 for (int i=0; i<manager.ItemCount; i++) {
123 int item = i + 1;
124 TraceData d = manager.TraceData [i];
125 TraceData.RenderAltRow (table, i, item.ToString (), d.RequestTime.ToString (),
126 d.RequestPath, d.StatusCode.ToString (), d.RequestType,
127 "<a href=\"Trace.axd?id=" + item + "\" class=\"tinylink\">" +
128 "<b><nobr>View Details</a>");
130 table.RenderControl (output);
133 output.RenderEndTag ();
134 output.RenderEndTag ();
136 output.RenderEndTag ();
139 private void RenderHeader (HtmlTextWriter output, string dir)
141 Table table = TraceData.CreateTable ();
142 TableRow row1 = new TableRow ();
143 TableRow row2 = new TableRow ();
144 TableCell cell1 = new TableCell ();
145 TableCell cell2 = new TableCell ();
146 TableCell cell3 = new TableCell ();
147 TableCell cell4 = new TableCell ();
149 cell1.Text = "<h1>Application Trace</h1>";
150 cell2.Text = "[ <a href=\"Trace.axd?clear=1\" class=\"link\">clear current trace</a> ]";
152 cell2.HorizontalAlign = HorizontalAlign.Right;
153 cell2.VerticalAlign = VerticalAlign.Bottom;
155 row1.Cells.Add (cell1);
156 row1.Cells.Add (cell2);
158 cell3.Text = "<h2><h2><p>"; // ummm, WTF?
159 cell4.Text = "<b>Physical Directory:</b>" + dir;
161 row2.Cells.Add (cell3);
162 row2.Cells.Add (cell4);
164 table.Rows.Add (row1);
165 table.Rows.Add (row2);
167 table.RenderControl (output);
170 private void RenderItem (TraceManager manager, HtmlTextWriter output, int item)
172 manager.TraceData [item - 1].Render (output);
175 [MonoTODO ("Appears in class status, but...")]
176 protected void ShowDetails (DataSet data)
180 [MonoTODO ("Appears in class status, but...")]
181 protected void ShowRequests (ArrayList list)