Hi folks,
I am trying to create some URL constraints for controllers to prevent null reference exceptions.
For example
/folder/edit/3 should be okay
/folder/edit/asdf shouldn't be okay
Instead of adding a Regex on every action method I want to use URL constraints for that.
The Problem I am facing right now is that the default route catches all requests, or if I am adding that constraint to the default route the standards request like http://host.tld/ aren't working anymore.
The constraint I am trying to add is
routes.MapRoute(
"RouteWithContraint",
"folder/edit/{id}",
new { controller="folder", action="edit", id="" },
new { id = @"\d+" }
);
Does anyone has a hint for me on how to solve that problem? Or maybe someone knows a best practice on DRY for "IsANumber" checks for ids?
best regards,
Gordon