If I understood well, you want to limit and put some constraints on values can pass as routing sections, You can do it with Route Constraint. Plaese read Creating a Route Constraint (C#) and you will find how that is possible. You can do it same as below:
routes.MapRoute(
"Product",
"Product/{productId}",
new {controller="Product", action="Details"},
new {productId = @"\d+" }
);
The regular expression \d+ matches one or more integers. This constraint causes the Product route to match the following URLs:
/Product/3
/Product/8999
But not the following URLs:
/Product/apple
/Product
Additionally you could write your custom route constraint, Please read Creating a Custom Route Constraint (C#) and see below sample I just copied from This post by Guy Burstein that I think you find it useful:
public class FromValuesListConstraint : IRouteConstraint
{
public FromValuesListConstraint(params string[] values)
{
this._values = values;
}
private string[] _values;
public bool Match(HttpContextBase httpContext,
Route route,
string parameterName,
RouteValueDictionary values,
RouteDirection routeDirection)
{
// Get the value called "parameterName" from the
// RouteValueDictionary called "value"
string value = values[parameterName].ToString();
// Return true is the list of allowed values contains
// this value.
return _values.Contains(value);
}
}
As Guy said: In order to implement a Custom Route Constraint, you should create a class that inherits from IRouteConstraint, and implement the Match method.
Hope this help.