All-Star
194490 Points
28079 Posts
Moderator
Oct 17, 2018 08:47 AM|Mikesdotnetting|LINK
Map a new route with a constraint:
routes.MapRoute( name: "", url: "{tel}", defaults: new { controller = "sales", action = "quotes" }, constraints: new {tel = @"\d{9}"} );
This will map any URL that consists of exactly 9 numbers (and nothing else) e.g. mydomain.com/123456789 to the "quotes" action on the "sales" controller. Register this before the default route. It won't affect existing routing.
https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/creating-a-route-constraint-cs
You will want to confirm the expected format of the telephone numbers with the customer and adjust the Regex expression in the constraint accordingly.
All-Star
194490 Points
28079 Posts
Moderator
Re: How to route using mydomain.com/PARAM
Oct 17, 2018 08:47 AM|Mikesdotnetting|LINK
Map a new route with a constraint:
This will map any URL that consists of exactly 9 numbers (and nothing else) e.g. mydomain.com/123456789 to the "quotes" action on the "sales" controller. Register this before the default route. It won't affect existing routing.
https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/creating-a-route-constraint-cs
You will want to confirm the expected format of the telephone numbers with the customer and adjust the Regex expression in the constraint accordingly.