The more I think about it, the more I find it possible to write my own route that will use these URL definitions:
{var1}/{var2}/{var3} Const/{var1}/{var2} Const1/{var1}/Const2/{var2} {var1}/{var2}/Const
as well as the presence of no more than one greedy parameter in any position in any of the upper URLs, for example
{*var1}/{var2}/{var3} {var1}/{*var2}/{var3} {var1}/{var2}/{*var3}
There is one important limitation . Routes with a greedy segment cannot have any additional parts. All of them are required .
Example
This is a sample request.
http:
This is a URL route definition
{action}/{*topicTree}/{id}/{title}
Algorithm
The Parsing request route inside GetRouteData() should work as follows:
- Split request into segments:
- Show
- Subject
- Subsection
- SubSubTopic
- 123
- This-this-en-example
- Determining the URL of the route route starting from the left, and assigning the values โโof one segment to the parameters (or matching the values โโof the request segment to static route segments)
- When a route segment is defined as greedy, reverse parsing and moving to the last segment.
- Parse route segments one by one back (assigning them query values) until you go back to the greedy trap.
- When you reach greedy again, merge all the remaining query segments (in the original order) and assign them to the greedy route parameter catch-all.
Questions
As far as I can think of it, it can work. But I would like to know:
- Someone already wrote this, so I don't need it (because there are other aspects of parsing that I didn't mention (restrictions, default values, etc.).
- You see flaws in this algorithm, because I have to write it myself if no one has done so far.
I did not think about the GetVirtuaPath() method at GetVirtuaPath() .
asp.net-mvc routing catch-all
Robert Koritnik
source share