Skip to content

Instantly share code, notes, and snippets.

@curtismitchell
Last active December 19, 2015 10:29
Show Gist options
  • Save curtismitchell/5940417 to your computer and use it in GitHub Desktop.
Save curtismitchell/5940417 to your computer and use it in GitHub Desktop.
MVC route constraint that does not match a set of words (with help from http://stackoverflow.com/questions/6277022/regex-not-matching-a-list-of-words)
/* must come before the default route (if still being used)
allows for routes like .../mycompany/projects/index/1
uses the constraint to make sure system controller names can co-exist with workspace names
*/
routes.MapRoute(
"Workspace",
"{workspace}/{controller}/{action}/{id}",
new { controller = "Projects", action = "Index", id = String.Empty },
new { workspace = @"^(?!.*\bAccount\b)(?!.*\bHome\b).*$" }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment