Created
June 1, 2012 19:52
-
-
Save Grummle/2854760 to your computer and use it in GitHub Desktop.
Http Module to write Route 'pattern' to server_variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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