Created
May 24, 2010 14:32
-
-
Save joeygreen/411934 to your computer and use it in GitHub Desktop.
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
public void Application_BeginRequest(Object sender, EventArgs e) | |
{ | |
// Check url | |
if (Regex.IsMatch(HttpContext.Current.Request.Url.ToString(), @"[A-Z]") == true) | |
{ | |
// Lowercase url | |
String lower = HttpContext.Current.Request.Url.ToString().ToLower(); | |
// Redefine response | |
HttpContext.Current.Response.Clear(); | |
HttpContext.Current.Response.Status = "301 Moved Permanently"; | |
HttpContext.Current.Response.AddHeader("Location", lower); | |
HttpContext.Current.Response.End(); | |
} | |
} // Application_BeginRequest | |
public class LowerRoute : Route | |
{ | |
public LowerRoute(String url, IRouteHandler handler) : base(url, handler) { } | |
public LowerRoute(String url, RouteValueDictionary defaults, IRouteHandler handler) : base(url, defaults, handler) { } | |
public LowerRoute(String url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler handler) : base(url, defaults, constraints, handler) { } | |
public LowerRoute(String url, RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary tokens, IRouteHandler handler) : base(url, defaults, constraints, tokens, handler) { } | |
public override VirtualPathData GetVirtualPath(RequestContext context, RouteValueDictionary values) | |
{ | |
VirtualPathData path = base.GetVirtualPath(context, values); | |
if (path != null) | |
path.VirtualPath = path.VirtualPath.ToLowerInvariant(); | |
return path; | |
} // VirtualPathData | |
} // LowerRoute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment