views:

19

answers:

1

Hello

I was planning on having 2char language in url, like something.com/EN, /ES, /US. Is that possible to add a 2char constraint for a route?

/M

+2  A: 

Yes u can do this by routeconstraints. constaints can be passed to Maproutes method in global.asax. if u have a constraint that can be handled by regex u can write it like

routes.MapRoute(
              "strict",
              "{controller}.mvc/{docid}/{action}/{id}",
              new {docid = "",action = "Index", id = ""},
              new { docid = @"\d+"}

            );

where regex pattern tells that docid should be numeric to match this route. however u can write ur own class that implements IRouteConstraint interface and object of that class can act as routeconstraint for ur route

take a look here to see how u can implement IRouteConstraint

Muhammad Adeel Zahid