Multiple RoutePrefixes per controller using MVC attribute routing?

With the new MVC Attribute routing, I know that you can assign multiple Route attributes to a single ActionResult , but I'm looking for a way to do the same at the RoutePrefix level. I have a controller that in each action should be accessible along three routes:

/Games/{Title}/Characters/{Route} /Books/{Title}/Characters/{Route} /Cinema/{Title}/Characters/{Route}

I tried to put three separate RoutePrefix attributes, but I get a Deuplace RoutePrefix attribute error. If I try to use a comma separated list, I get the Best override method for does not contain a constructor that takes 3 arguments .

Is it possible to configure RoutePrefix so that there are three routes for my controller?

+6
source share
1 answer

Running a bunch of tests, I found that I can simply add 3 Route attributes to the controller level, and it works the way I want.

Edit: The best way to do this I found using the regex matching method

[RoutePrefix("{Type:regex(Games|Cinema|Books)}/{SectionRoute}/Character/")]

+13
source

Source: https://habr.com/ru/post/971476/


All Articles