Skip to content

Instantly share code, notes, and snippets.

@Grummle
Created June 1, 2012 19:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Grummle/2854760 to your computer and use it in GitHub Desktop.
Save Grummle/2854760 to your computer and use it in GitHub Desktop.
Http Module to write Route 'pattern' to server_variables
using System;
using System.Diagnostics;
using System.Web;
using System.Web.Routing;
using YourApp.Infrastructure.Framework;
namespace YourApp.Web.UI
{
public class RestfulRouteModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.LogRequest+= new EventHandler(context_LogRequest);
}
void context_LogRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext context = app.Context;
context.Request.ServerVariables["ROUTE_PATTERN"] = context.Request.RequestContext.RouteData.Route.IsNotNull() ? ((Route)context.Request.RequestContext.RouteData.Route).Url : context.Request.Url.LocalPath;
}
public void Dispose()
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment