I have set up the following route in my MVC project:
routes.MapRoute(
"Product",
"product-{pathname}-{productId}",
new { controller = "Product", action = "ProductPage" });
This works fine for urls like product-test-title-1234
but if the pathname
bit of the url contains product-
, a 404 gets thrown - Is there a way to allow for a url like product-test-product-title-1234
?
Weirdly, if I put the second product just before the product id (eg product-test-title-product-12345
), then the route works and the page is displayed, anywhere else and it throws a 404
Update
I think the problem may lie with the fact that 2 parts of the url match the route so I guess my question is how do you ensure that the route says that first product must be at the start of the url (and count any further instances of product as part of the pathname).
After further testing, I have found that instead of going to the product controller, this url goes to my catchall route: {*pathname}
- not sure why this happens