Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greedy segment with .NET MVC 5 Attribute Routing

I would like to define a route as follows -

[Route("clients/{*code}/{id:guid}/update")]
public ActionResult Update(string code, Guid id)
{
}

Code will be something like "foo/bar/xyz".

Unfortunately, out-of-the-box MVC doesn't support greedy parameters in the middle of a Route definition.

This has previously been solved using the old MVC routing conventions, however I would like to have this as a RouteAtribute defintion.

like image 949
jameskind Avatar asked May 05 '15 15:05

jameskind


Video Answer


1 Answers

As far as I know you cannot do it directly. However, you should be able to use IIS module UrlRewrite and rewrite the query with a greedy parameter in the middle to the one with a greedy parameter at the end.

So a client queries: clients/{*code}/{id:guid}/update and your web api sees clients/{id:guid}/update/{*code}

like image 118
milanio Avatar answered Oct 19 '22 12:10

milanio