BuzzBubba
BuzzBubba

Reputation: 733

ASP.NET MVC catch the rest of the route url

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/2612010/2828/en/articles/october/asking-the-overflow/madd.aspx

read 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.

Upvotes: 0

Views: 278

Answers (1)

BuzzBubba
BuzzBubba

Reputation: 733

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.

Upvotes: 1

Related Questions