I would like to learn how do I make a "catch the rest" route in ASP.NET MVC?
I need to take formated urls, read some data to it's values, and take the remainder of the link and SAVE it to some variable so I can read it later and generate a link. blog.mydomain.com/linker/process/261201开发者_如何学JAVA0/2828/en/articles/october/asking-the-overflow/madd.aspxread like:
memberid = 2612010 memberrating = 2828 language = en restofurl = "articles/october/asking-the-overflow/madd.aspx"or this link: blog.mydomain.com/linker/process/2612010/2828/en/articles/october/read.aspx?m=828
read like:
memberid = 2612010
memberrating = 2828 language = en restofurl = "articles/october/read.aspx?m=828"or
blog.mydomain.com/linker/process/2612010/2828/en/articles
to: memberid = 2612010 memberrating = 2828 language = en restofurl = "articles"I've considered something like:
routes.MapRoute(
"Linker", // Route name
"Linker/Process/{memberid}/{memberrating}/{lang}/{*other}", // ULR with parameters
new { controller = "Linker", action = "Process", lang = "en", other = UrlParameter.Optional}
);
This route picks up the rest of the link correctly, but ommits URL parameters at the end of: blog.mydomain.com/linker/process/2612010/2828/en/articles/october/read.aspx?m=828
and displays only articles/october/read.aspx
as the "restofurl" value. I don't need classic url get params assignet to anything, just want them part of the restofurl variable.I will answer this myself.
var restofurl =
String.Format("{0}?{1}", RouteData.Values["other"], Request.QueryString);
Will effectively construct a correct url. If you happen to find a "cleaner/nicer" way of doing it, please post.
精彩评论