Skip to content

Instantly share code, notes, and snippets.

@jpoehls
Forked from Grummle/RestfulRouteModule.cs
Created July 25, 2012 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpoehls/3177680 to your computer and use it in GitHub Desktop.
Save jpoehls/3177680 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