Skip to content

Instantly share code, notes, and snippets.

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 joeygreen/411934 to your computer and use it in GitHub Desktop.
Save joeygreen/411934 to your computer and use it in GitHub Desktop.
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