Edit: I need to re-open my question because it is not a RegEx Problem! The problem resides in the forward slash. Even if the RegEx matches I won't get the desired result in my controller action. ASP.NET Core does not map path segments if they contain a forward slash. And I'm looking for a workaround in terms of a middleware, routing options, whatever exists.
I'm looking for a solution to get several path segments from the calling url within my controller action including the forward slash via RegEx constraint.
Example:
The user calls: PUT api/v1/model/elements/elementCollection1/subElement1/subSubElement2/value
Now everything between elements/
and /value
shall be passed to an action parameter called elementPath
in a function like...
[HttpPut("api/v1/model/elements/{elementPath}/value")]
public IActionResult PutElementValue(string elementPath, [FromBody] Value value)
{
//Here is code
}
Do you have an idea how to RegEx and map tge match to the elementPath parameter including forward slash? Something like:
[HttpPut("api/v1/model/elements/{elementPath:regex(<Here shall be the right RegEx>)}/value")]
It's worth notice that I tried also with * catch-all parameters and it was kind of a hack but it worked for a moment. The problem is that I have another Put-Operation on api/v1/model/elements/{elementPath} without the "/value" appendix. Hence I'm forced to get the elementPath the right way. Plus I want to auto-generate a Swagger Doc from the Controller and everything inside and hacks are not parsed.
Please help and excuse me - this is my first question on StackOverflow.