-
-
Save jpoehls/3177680 to your computer and use it in GitHub Desktop.
Http Module to write Route 'pattern' to server_variables
This file contains hidden or 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