Skip to content

Instantly share code, notes, and snippets.

@lennybacon
Created February 17, 2018 15:40
Show Gist options
  • Save lennybacon/3418edd4e28761520fdcfc1ca2e8aaa1 to your computer and use it in GitHub Desktop.
Save lennybacon/3418edd4e28761520fdcfc1ca2e8aaa1 to your computer and use it in GitHub Desktop.
An ASP.NET Handler illustrating the usage of the W3C Server Timing HTTP Header
<%@ WebHandler Language="C#" Class="Samples.MyHandler" %>
using System;
using System.Web;
namespace Samples
{
/// <summary>
///TODO:DESCRIPTION HERE
/// </summary>
public class MyHandler
: IHttpHandler
{
/// <inheritdoc />
public void ProcessRequest(HttpContext context)
{
context.Response.AddHeader(
"Server-Timing",
"cache;desc=\"Cache Read\";dur=23.2," +
"cache;desc=\"Cache Write\";dur=103.4," +
"db;desc=\"Database Read\";dur=43.02," +
"db;desc=\"Database Write\";dur=101.6," +
"logic;desc=\"Logic\";dur=21.9," +
"serialization;desc=\"Serialization\";dur=41.09,");
context.Response.ContentType = "text/html";
context.Response.Write("<html>");
context.Response.Write("<head>");
context.Response.Write("<title>Server Timing Sample</title>");
context.Response.Write("<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\" integrity=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"anonymous\">");
context.Response.Write("</head>");
context.Response.Write("<body>");
context.Response.Write("<div class=\"container\">");
context.Response.Write(" <div class=\"row\">");
context.Response.Write(" <div class=\"col-12\">");
context.Response.Write(" <h1 class=\"display-4\">");
context.Response.Write(" Server Timing Sample");
context.Response.Write(" </h1>");
context.Response.Write("<p class=\"lead\">");
context.Response.Write(" The following data, if present, was sent by the server through the W3C Server Timing HTTP Header and used by the client side API from JavaScript.");
context.Response.Write("</p>");
context.Response.Write(" </div>");
context.Response.Write(" </div>");
context.Response.Write(" <div class=\"row\">");
context.Response.Write(" <div class=\"col-12\">");
context.Response.Write("<script src=\"./ServerTiming.js\"></script>");
context.Response.Write(" </div>");
context.Response.Write(" </div>");
context.Response.Write("</div>");
context.Response.Write("</body>");
context.Response.Write("</html>");
}
/// <inheritdoc />
public bool IsReusable
{
get
{
return true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment