//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//------------------------------------------------------------------------------
/*
* Trace Handler
*
* Copyright (c) 1998-1999, Microsoft Corporation
*
*/
namespace System.Web.Handlers {
using System;
using System.Collections;
using System.Web;
using System.Globalization;
using System.Web.Configuration;
using System.Web.Hosting;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Util;
using System.Web.SessionState;
using System.Data;
using System.Text;
using System.Drawing;
using System.Security.Permissions;
///
/// [To be supplied.]
///
public class TraceHandler : IHttpHandler {
private const string _style =
"\r\n";
private HttpContext _context;
private HttpResponse _response;
private HttpRequest _request;
private HtmlTextWriter _writer;
[SecurityPermission(SecurityAction.Demand, Unrestricted=true)]
public TraceHandler() {
}
// IHttpMethods exposed to derived classes
protected void ProcessRequest(HttpContext context) {
((IHttpHandler)this).ProcessRequest(context);
}
protected bool IsReusable {
get {
return ((IHttpHandler)this).IsReusable;
}
}
void IHttpHandler.ProcessRequest(HttpContext context) {
// VSWhidbey 448844: Disable handler if retail is set to true
if (DeploymentSection.RetailInternal ||
(!context.Request.IsLocal && HttpRuntime.Profile.LocalOnly)) {
HttpException e = new HttpException(403, null);
e.SetFormatter(new TraceHandlerErrorFormatter(!DeploymentSection.RetailInternal));
throw e;
}
_context = context;
_response = _context.Response;
_request = _context.Request;
_writer = Page.CreateHtmlTextWriterInternal(_response.Output, _request);
// if we're in integrated mode, we need to set the content type explicitly
if (context.WorkerRequest is IIS7WorkerRequest) {
_response.ContentType = _request.Browser.PreferredRenderingMime;
}
if (_writer == null) {
// Can't create a writer, horked at this point, just return
return;
}
_context.Trace.IsEnabled = false;
// Validate the input to prevent XSS attacks.
_request.ValidateInput();
_writer.Write("\r\n");
_writer.Write("
\r\n");
_writer.Write(StyleSheet);
_writer.Write("\r\n");
_writer.Write("\r\n");
_writer.Write("\r\n");
if (!HttpRuntime.Profile.IsConfigEnabled) {
HttpException e = new HttpException();
e.SetFormatter(new TraceHandlerErrorFormatter(false));
throw e;
}
IList datasets = HttpRuntime.Profile.GetData();
// first check if we should clear data
if (_request.QueryString["clear"] != null) {
HttpRuntime.Profile.Reset();
string url = _request.RawUrl;
_response.Redirect(url.Substring(0, url.IndexOf("?", StringComparison.Ordinal)));
}
// then check if we are drilling down
string strid = _request.QueryString["id"];
if (strid != null) {
int index = Int32.Parse(strid, CultureInfo.InvariantCulture);
if (index >=0 && index < datasets.Count) {
ShowDetails((DataSet) datasets[index]);
ShowVersionDetails();
_writer.Write("\r\n\r\n\r\n");
return;
}
}
// if we get here, its just generic request
ShowRequests(datasets);
ShowVersionDetails();
_writer.Write("\r\n