I want to set up a route that will match on any url, with a constraint. This is what I have tried:
routes.MapRouteLowercase("CatchAll Content Validation", "{*url}",
new { controller = "Content", action = "LoadContent" },
new { url = new ContentURLConstraint(), }
);
and for testing purposes I have the following simple constraint:
public class ContentURLConstraint : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
var s = (string)values["url"];
return s.Contains("comm");
}
}
If the constraint is satisfied I when expect to pass the full url to the controll action LoadContent
public ActionResult LoadContent(string url)
{
return Content(url);
}
I am expecting, when I load a page, for s in the Match function to contain the entire url, so that I can check it, but instead it is null. What might I be missing?
valuesobject looks like within the method.