Suppose I have these actions
- http://thesite.com/Cats/product/1
- http://thesite.com/Cats/1
My customer wants a dynamic way to define custom URL for these actions because of SEO things.
So I cant use Redirects!
Ex.
http://thesite.com/aaaaaa
to openhttp://thesite.com/Cats/product/1
http://thesite.com/bbbbbb
to openhttp://thesite.com/Cats/product/1
, Again!http://thesite.com/cccccc
to openhttp://thesite.com/Cats/1
How do you setup routing for this dynamic behavior.
Again, I CANT USE RedirectToAction
Bests,
Thank you in advance.
2
Answers
You need to create a custom DynamicRouteValueTransformer
The register the service and configure the routing in
Startup
class.According to your description, I suggest you could also use custom middleware to achieve your requirement.
You could check the request’s path in the custom middleware and modify the request path.
More details, you could refer to below codes: