ASP.NET MVC Combine two routes into one
Is there any way to combine these two routes strings: {language}/item/{itemId}/proreviews and item/{itemId}/proreviews into one route?
UPD. {language} is optional
UPD2. The workflow is the following: user enters domain.com/item/1/proreviews and I redirect him to the url with the appropriate country code like开发者_开发技巧 domain.com/en/item/1/proreviews. Now I am implementing localization and I really don't want to duplicate all my currrent (countrycode-less) routes.
Routes accept regular expressions. You can come up with a Regular Expression that matches the cultures you support. Just put that route above the default route and it should fall through.
Other possibilities include putting the language in a cookie or perhaps as the subdomain (en.domain.com/item/1/proreviews).
Why don't you just make {language} the last parameter, then it's easy to make it optional.
Why not create a single rewrite rule so that any urls that do not start with a country code in have the language automatically added in (presumably with /en/ in instead).
This way, you will only have one route as IIS will pass the request on to MVC with the language in, and your user will be none the wiser.
This also means that language will be optional.
I should point out though that you should probably 301 these rewrites, otherwise, it's quite likely that you'll suffer SEO consequences as a result of having duplicate content at different urls (/en/item/1234/proreviews
will have the same content as /item/1234/proreviews
).
精彩评论