URL routing documentation question
I'm reading about URL routing at How to: Define Routes for Web Forms Applications a开发者_如何学Gond there's something in the example I don't understand. If you look at the example provided below,
routes.MapPageRoute("", "SalesReport/{locale}/{year}/{*queryvalues}", "~/sales.aspx");
specifically at
"SalesReport/{locale}/{year}/{*queryvalues}"
Why does queryvalues have an asterisk in front of it and locale and year don't?
The * indicates a "catch all" parameter, which essentially matches everything else in the requested URL.
Everything after the "year" parameter in the URL will get dumped into the queryvalues parameter. So for example, the URL
http://whatever/SalesReport/canada/1999/x=1
will give you a queryvalues variable populated with "x=1"
. But it will also match the URL
http://whatever/SalesReport/canada/1999/x=1/y=2/z=3
and queryvalues will be populated with "x=1/y=2/z=3"
.
You can only have one catch-all parameter in your route, and it has to be the final parameter.
精彩评论